Created
April 11, 2014 04:26
-
-
Save jakeboxer/10440844 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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