在Ruby中,我如何从父类访问调用类的常量?
Module Foo
class Base
def test()
#how do I access calling class's constants here?
#ex: CallingClass.SOME_CONST
end
end
end
class Bar < Foo::Base
SOME_CONST = 'test'
end
Foo::Base
,并拥有它们自己不同的常量?除了常量之外,所有子类的test
方法是否都相同? - jstimtest()
是所有子类都应该继承的方法,但它依赖于每个子类之间不同的常量。 - doremi