From: Robert Klemme Date: 2009-11-18T05:00:16+09:00 Subject: Re: How to dynamically include a module and update top level? On 17.11.2009 00:30, Alexandre Mutel wrote: > Robert Klemme wrote: >> On 16.11.2009 22:01, Alexandre Mutel wrote: >> Basically "include" behaves as if the inheritance chain at the time of >> inclusion is copied. > > Thanks for your response. So it seems that every time a module is > mixed-in another top-module, i have to reinclude the top-module into its > includers? Apparently: irb(main):001:0> module A; end => nil irb(main):002:0> c=Class.new { include A } => # irb(main):003:0> c.ancestors => [#, A, Object, PP::ObjectMixin, Kernel, BasicObject] irb(main):004:0> module B; end => nil irb(main):005:0> module A; include B; end => A irb(main):006:0> c.ancestors => [#, A, Object, PP::ObjectMixin, Kernel, BasicObject] irb(main):007:0> c.class_eval { include A } => # irb(main):008:0> c.ancestors => [#, A, B, Object, PP::ObjectMixin, Kernel, BasicObject] irb(main):009:0> > I tried the following "hack" and seems to work, I would be glad to have > some feedback... not sure it's a good ruby habit... even if it's > working! Personally I find that the more interesting question. Do you want to have the side effect of updating potentially many classes (and objects via their class and #extend)? Maybe there is a better design choice? I don't know your use case or what you need that behavior for. Generally Matz pics _very_ reasonable choices so I tend to assume that the aforementioned side effect is usually not wanted. Which does not mean that there is no use case for this. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/