看了http://ruby-china.org/topics/10654 7 楼的例子,很受启发。
一、静态位置(Module.nesting)优先 include。
module M ; N = 1; end
module M2
N=2
class C
include M
def self.n; N; end
end
end
M2::C.n #=>>2
.. 二、静态位置优先继承
class C1; N=1 ; end
class C2
N=2 #位置优先继承
class C3 < C2
def self.n; N ; end
end
end
C2::C3.n #=>2
.. 三、include 优先继承
class C5; N=1 ; end
module M3; N=2 ; end
class C55 < C5
include M3 #include优先继承
def self.n; N; end
end
C55.n #=>2