module A def doit puts 'A doit' end end module B def doit puts 'B doit' end end module C def self.included(base) base.prepend(InstanceMethods) end module InstanceMethods def doit puts 'C doit' end end end module D def self.included(base) base.class_eval do def doit puts 'D doit' end end end end class Foo include A end f = Foo.new puts Foo.ancestors.inspect f.doit puts '---- B ----' # Not working A.include(B) puts A.ancestors.inspect puts Foo.ancestors.inspect f.doit puts '---- C ----' # Not working A.include(C) puts A.ancestors.inspect puts Foo.ancestors.inspect f.doit puts '---- D ----' # Working A.include(D) puts A.ancestors.inspect puts Foo.ancestors.inspect f.doit
Standard input is empty
[Foo, A, Object, Kernel, BasicObject] A doit ---- B ---- [A, B] [Foo, A, Object, Kernel, BasicObject] A doit ---- C ---- [C::InstanceMethods, A, C, B] [Foo, A, Object, Kernel, BasicObject] A doit ---- D ---- [C::InstanceMethods, A, D, C, B] [Foo, A, Object, Kernel, BasicObject] D doit