class Person
def initialize(name)
@name = name
end
end
class Employee < Person
end
emp = Employee.new # throws error wrong number of arguments
emp = Employee.new("foo") # parent class initialize method is called
class Employee < Person
def initialize(name, designation)
super(name)
@designation = designation
end
end
emp = Employee.new("foo", "bar")
Last active
March 8, 2017 07:20
-
-
Save sandheepg/bc9a9e17db7447537d32c5801465adc5 to your computer and use it in GitHub Desktop.
Calling super in initialize method of Ruby
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment