我的基类中有一个方法,我需要从我的派生类中调用这个方法。是否可以使用静态方法?
class base < A
def self.method1
end
end
class derived < base
def method2
base.method1
end
end
这样可以吗?是否正确?
最佳答案
是的..
class Base
def self.method1
p "hi"
end
end
class Derived < Base
def method2
self.class.method1
end
end
Derived.new.method2
# >> "hi"
关于ruby - 从派生类方法调用基类方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18052136/