On Jun 16, 2007, at 9:56 AM, Robert Dober wrote:

> Hi list
>
> I just observed this (and it cost me quite some effort to debug my  
> code :( )
>
> 515/15 > ruby -ve 'class << Class::new; puts self; puts  
> ancestors.inspect end'
> ruby 1.8.5 (2006-12-04 patchlevel 2) [i686-linux]
> #<Class:#<Class:0xb7dfae50>>
> [Class, Module, Object, Kernel]
>
>
> this seems to be in contradiction with
> http://www.ruby-doc.org/core/classes/Module.html#M001700
> stating
> ---------------------------------------------------------------------- 
> -------
>  mod.ancestors вк array
>
> Returns a list of modules included in mod (including mod itself).
>                                                                  
> =============
>
>   module Mod
>     include Math
>     include Comparable
>   end
>
>   Mod.ancestors    #=> [Mod, Comparable, Math]
>   Math.ancestors   #=> [Math]
> ---------------------------------------------------------------------- 
> -----
>
> Is this an error in doc or in behavior?

It cost me some effort to figure out what the question really  
was :),  but I presume you're wondering why the singleton class  
doesn't appear in the ancestor list. I don't know the answer, but I  
think the question is posed more clearly when the example is  
constructed for the singleton class of an ordinary object.

<code>
class Foo; end
Bar = class << Foo.new; self; end
Bar # => #<Class:#<Foo:0x20e18>>
Bar.ancestors # => [Foo, Object, Kernel]
</code>

If I had to make a call, I would say that the documentation had  
inadvertently omitted a very special case.

Regards, Morton

P.S. Why 'puts ancestors.inspect' instead of the simpler 'p ancestors'?