P
Paolo Nusco Perrotta
Try this:
module M
def hello; p 'M'; end
end
class C
def hello; p 'C'; end
end
class D < C; end
class C; include M; end
class D; include M; end
D.ancestors -> [D, C, M, Object, Kernel]
D.new.hello -> "C"
Now restart from a clean slate and change the last few lines:
class D; include M; end
class C; include M; end
D.ancestors -> [D, M, C, M, Object, Kernel]
D.new.hello -> "M"
Ruby silently prevents you from including a module that has been
included by an ancestor. Why?
module M
def hello; p 'M'; end
end
class C
def hello; p 'C'; end
end
class D < C; end
class C; include M; end
class D; include M; end
D.ancestors -> [D, C, M, Object, Kernel]
D.new.hello -> "C"
Now restart from a clean slate and change the last few lines:
class D; include M; end
class C; include M; end
D.ancestors -> [D, M, C, M, Object, Kernel]
D.new.hello -> "M"
Ruby silently prevents you from including a module that has been
included by an ancestor. Why?