这是我尝试过的方法:
module A
def self.method1; "method1"; end
def method2; "method2"; end
end
module B; include A; end
B.method1 # => error
B.method2 # => error
B::method1 # => error
B::method2 # => error
我希望避免在两个模块之间复制和粘贴等效代码。我之所以在这里使用模块而不是类,是因为我不需要每个模块的多个实例,因为它们仅仅保存常量(其他模块,在此时点)。
什么是解决这个问题的最佳方法?