Hi --

On Sun, 11 Sep 2005, Michael Schuerig wrote:

>
> (1) Under what circumstances is an array not an Array? I'm confronted
> with such a case in one of my unit tests. The test failed when run in
> conjunction with other tests and I narrowed it down to this: In the
> tested code I use something.kind_of?(Array). I have a mixin module that
> extends Array with additional methods. When this module is required
> directly or indirectly in my test class then kind_of?(Array) doesn't
> behave as expected anymore.

Can you provide a complete (non-)working example?  I can't quite
reconstruct it from this.

> (2) Maybe I'm not understanding Ruby's object system well enough. That
> appears to be true in another case, too. I have a mixin module for
> Enumerable whose methods I want to use on arrays, too, of course. But
> apparently it is not enough to include it in Enumerable
>
> Enumerable.module_eval do
>  include MyEnumExt
> end
>
> I have to do the same for Array to make it available there
>
> Array.class_eval do
>  include MyEnumExt
> end

You could also re-include Enumerable in Array after you've changed
Enumerable.  Still, it does seem like some kind of optimization or
special case for built-ins.  If you make your own the changes are
propagated:

   module M
     def x; 1; end
   end

   class D
     include M
   end

   D.new.x    # 1

   module M
     def y; 2; end
   end

   D.new.y    # 2


David

-- 
David A. Black
dblack / wobblini.net