假设我拥有从A类派生的类BRuby:调用子类中的父类的重写方法
是否可以像这样调用A的overrided方法?
class A
def method1
end
def method2
end
end
class B < A
def method1
### invoke method2 of class A is what I want to do here
end
def method2
end
end
#不完全重复到How do I call an overridden parent class method from a child class?,但我们似乎想要做同样的事情。
您的意思是说您的示例代码中B是A的子类? – sepp2k 2011-12-23 13:07:11
如果b是一个子类,那么你可以简单地在你的b中调用super。 – three 2011-12-23 13:10:09
不,他需要从后代的方法1调用super的method2。在Ruby中没有办法(我知道)要做到这一点。 – 2011-12-23 13:21:06