Skip to content

Instantly share code, notes, and snippets.

@jakeboxer
Created April 11, 2014 04:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jakeboxer/10440844 to your computer and use it in GitHub Desktop.
Save jakeboxer/10440844 to your computer and use it in GitHub Desktop.
class Parent
def dope_method(arg1 = nil, arg2 = nil)
puts "Called Parent#dope_method(#{arg1.inspect}, #{arg2.inspect})"
end
end
class Child < Parent
def dope_method(arg1, arg2)
puts "Called Child#dope_method(#{arg1.inspect}, #{arg2.inspect})"
# No parentheses
super
end
end
c = Child.new
c.dope_method("arg1", "arg2")
# Called Child#dope_method("arg1", "arg2")
# Called Parent#dope_method("arg1", "arg2")
class Child < Parent
def dope_method(arg1, arg2)
puts "Called Child#dope_method(#{arg1.inspect}, #{arg2.inspect})"
# Parentheses!
super()
end
end
c = Child.new
c.dope_method("arg1", "arg2")
# Called Child#dope_method("arg1", "arg2")
# Called Parent#dope_method(nil, nil)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment