class Parent
def test
return
end
end
class Child < Parent
def test
super
p "HOW IS THIS POSSIBLE?!"
end
end
c = Child.new
c.test
I though that, since the test method from the Parent class immediately uses the return statement, it should not be possible to print the line of the Child class. But it is indeed printed. Why is that?
Ruby 1.8.7, Mac OSX.
superacts like a method call that calls the superclass’s method implementation. In your example, thereturnkeyword returns fromParent::testand continues executingChild::test, just like any other method call would.