module M
def func1_in_M
@some_popular_name = 'some data needed for M'
end
def func2_in_M
p @some_popular_name
end
end
class C
include M
def initilaize
@some_popular_name = "some data needed for C, but this guy didn't know what are used in M"
end
def func1_in_C
p @some_popular_name
end
end
o = C.new
o.func1_in_M
o.func1_in_C # => "some data needed for M"
这个结果显然不是 C 类程序员所期望的。多模块混合/多子分类也很容易发生这种问题。有什么好的建议可以避免这种情况吗?@ var ... 仍然可能导致相同的结果。name-mangling-related-to-module.__id?如何?