Created
January 17, 2015 18:25
-
-
Save mitio/add6a8dea5b493b5313a to your computer and use it in GitHub Desktop.
This file contains hidden or 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 Person | |
def greet(name) | |
puts "Hello, #{name}!" | |
end | |
end | |
# This will fail with the following error: | |
# ArgumentError: wrong number of arguments (2 for 1) | |
# This is because `super` calls Person#greet('Sir', 'Lancelot') | |
class NoblePerson < Person | |
def greet(name, title) | |
super | |
end | |
end | |
NoblePerson.new.greet 'Lancelot', 'Sir' | |
# This could work: | |
class NoblePerson < Person | |
def greet(name, title) | |
super("#{title} #{name}") | |
end | |
end | |
NoblePerson.new.greet 'Lancelot', 'Sir' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment