From: Rick DeNatale Date: 2007-03-24T03:26:03+09:00 Subject: Re: What is the problem with this module function. On 3/22/07, Phrogz wrote: > Ruby looks in E, then D, then M, then C, then B, then A. The reason > (or at least a reason that makes sense to me) is: > > a) Look in yourself before you look any higher. > b) Modules explicitly included in yourself are more important than > your superclass. This is in general true, however, there's a quirk, module M def foo p 'M::foo' end end class A include M end class B < A def foo p 'B::foo' end end class C < B include M end Now for the quiz A.new.foo ==> "M::foo" B.new.foo ==> "B::foo" C.new.foo ==> ? Now you might expect that since C explicitly re-included M that it should be "M::foo", however instead it's "B::foo". I know why this happens based on what the implementation of module inclusion does, I don't understand WHY it does it that way. It's just the way it is. For a time, Ruby1.9 allowed re-inclusion of a module by a subclass and C.new.foo DID return "M::foo", but for some reason, the current 1.9 (or at least the latest version I've gotten from SVN) has gone back to the old behavior. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/