Skip to content

Instantly share code, notes, and snippets.

@mitio
Created January 17, 2015 18:25
Show Gist options
  • Save mitio/add6a8dea5b493b5313a to your computer and use it in GitHub Desktop.
Save mitio/add6a8dea5b493b5313a to your computer and use it in GitHub Desktop.
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