0
如何将基类中的调用委托给基类实现而不是继承的类实现?例如:委托给基类实现
class A
def foo
p "hello"
end
def bar
foo
end
end
class B < A
def foo
p "world"
end
end
A.new.bar
# prints "hello"
B.new.foo
# prints "world"
B.new.bar
# prints "world"
# the function should print "hello" instead
在上面的例子中,什么是打印hello
当foo
方法由bar
方法的基类中调用最优雅的方式?