【发布时间】:2014-03-11 20:53:23
【问题描述】:
我想在父类中访问派生类的方法。请指教
Class A
def methodA
end
def methodB
end
end
Class B < Class A
def methodC
end
def methodD
end
end
我想在methodB里面调用methodD
Class A
def methodA
end
def methodB
methodD
end
end
谢谢。
【问题讨论】:
-
非常奇怪的要求..需要破解:p
-
这实际上是 OOP 中的一种标准做法,称为polymorphism。基本上,类
A对methodD的调用没有在代码中的那一点定义;可以说,它的多态取决于哪个派生类调用它。