From: Robert Dober Date: 2007-06-17T03:36:35+09:00 Subject: Re: Error in ancestor? On 6/16/07, Morton Goldberg wrote: > 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 I know in ruby I would say assert didactic_skills.zero? # :( > 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] > Sure thanks for adding this > > If I had to make a call, I would say that the documentation had > inadvertently omitted a very special case. Very probable given the code in class.c > > Regards, Morton > > P.S. Why 'puts ancestors.inspect' instead of the simpler 'p ancestors'? Because output is shorter and more readable. I often get bitten by debugging output puts ary1 puts ary2 ### Where the heck does ary2 start? so I developed a reflex to use inspect for all kind of debugging/demonstrating output. I feel it is goo[df] practice. Cheers Robert > > -- You see things; and you say Why? But I dream things that never were; and I say Why not? -- George Bernard Shaw