0
这里访问的一些代码演示行为我说的是:当我包括另一个已经被列入一类的模块,新的方法不是对类
module A
def foo; end
end
# initialize B with no methods
module B; end
class C
include B
end
# add methods to B
module B
def foo; end
include A
end
C.new.foo
C.new.bar # error: instance method bar is not defined for C
所以def
添加到B的内容被反映在C中,而添加的include
不是(除非B被重新包括在内)。为什么是这样,并且有一个干净的方法呢?
'bar'应该来自哪里?我在'A'和'B'中看到'foo',但在任何地方都看不到'bar'。 – 2013-05-06 04:50:36