Could anybody suggest what am i suppose to do for below problem.
Class Base
def age
return 18
end
def getOldAge
age
end
end
Class Der < Base
def age
return 19
end
end
ob = Der.new()
ob.getOldAge()
above run command will give me output as 19. Because its now overridden
by Der class and its ‘age’ method.
So,
Question is
Is it possible for getOldAge method from base class to call its own
class method age? Means which returns 18, not 19. In base class, i
should have control for accessing only my class method regardless of
overriding existing class by some else class.
Is it possible for getOldAge method from base class to call its own
class method age? Means which returns 18, not 19. In base class, i
should have control for accessing only my class method regardless of
overriding existing class by some else class.
looks awkward but possible
in class Base
def getOldAge
Base.instance_method(:age).bind(self).call
end
–
OZAWA Sakuro
“I think we can agree, the past is over.” - George W. Bush