【发布时间】:2016-06-15 20:47:00
【问题描述】:
是否可以从嵌套类方法调用模块的类方法?例如,如果我有:
module A
def self.foo
'hello'
end
end
module A
class B
def self.bar
foo # Fails since A is not in B's ancestor chain
end
end
end
我知道我可以通过使用直接在A 上调用foo
def self.bar
A.foo
end
但理想情况下,如果可能的话,我希望有一种方法让A 成为B 的祖先链的一部分。任何提示将不胜感激。
【问题讨论】:
-
可能没有办法绕过它,尝试使用类而不是模块。
标签: ruby-on-rails ruby oop