> Far as I know, Ruby finds methods by getting a list of an object's ancestors
> and extracting all implementations of the method from those modules. Walking
> up a series of parent classes takes linear time so it's not expensive for
> classes to see stuff added to their parents, but walking and flattening a
> multiple inheritance tree could be exponential time so it makes sense to
> cache ancestor trees when things like #include are called, effectively
> blocking a class from seeing changes to its mixins' ancestry.

Indeed, if every module had pointers to other included modules, I
definitely see how you'd end up with a very expensive object graph to
traverse to find method definitions.  Using the wonders of ruby, I
found a (rudimentary)way you can easily implement this though(see
below).  Its just a more generalized version of what I have above.  If
the only consideration is performance, I don't think its that much of
a hit(depending on your ObjectSpace), plus when you do any
metaprogramming I don't think performance is a major concern.  In this
case, any performance hit will occur only once at "include-time" and I
can't really envision injecting modules of code at any great rate -
although maybe this is just my short-sightedness :)  Anywhere, here's
the workaround:

class Module;
  def included(base)
   return unless(base.class == Module)
   ObjectSpace.each_object(Class){|o|
    next unless o.ancestors.include?(base)
    o.send(:include, self)
   }
  end
end

A simple benchmark on my system with irb and the example taken from
Eigenclass's page:
>> require 'benchmark'
>> class Module; def included(base); return unless(base.class == Module);ObjectSpace.each_object(Class){|o| next unless o.ancestors.include?(base);o.send(:include, self)};end;end
>> Benchmark.realtime{                                                                                                                                ?> module A; end
>> class C; include A end
>> module B; def foo; "B#foo" end end
>> module A; include B end
>> class D; include A end
>> }
=> 0.00185704231262207

not too shabby, no?