class A
def initialize
print "Hello! "
end
end
class B < A
def initialize(name)
super
print "My name is #{name}!"
end
end
test = B.new("Fred")
And I get
wrong number of arguments (1 for 0)
But why? Class B
requires one argument, and I am giving it all right. Class A
doesn't require any argument, so I am not passing anything through super
at all.
You need to use super() in order to call it with no arguments. Super by itself automatically calls the parent with the arguments provided to itself (ie. "Name")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With