From: Morton Goldberg Date: 2007-06-17T01:52:55+09:00 Subject: Re: Error in ancestor? 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, 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. class Foo; end Bar = class << Foo.new; self; end Bar # => #> Bar.ancestors # => [Foo, Object, Kernel] 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'?