From: Brian Mitchell Date: 2006-11-28T01:34:58+09:00 Subject: Re: [ ruby-Bugs-6820 ] #ancestors never includes the singleton class (inconsistent) On 11/27/06, Sylvain Joyeux wrote: > > It is supposed to. Singleton classes (or eigenclasses, if you want to > > call them) are not real classes, they are placeholders for per object > > attributes, so that they are not covered by #ancestors. > > > > matz. > And, out of curiosity, why do you want that ? The singleton classes look > like the "class of a single object" in (almost) every way. In 1.9 you > event made it inherit the "real" class of the object. So, why keeping this > kind of reminder that we can't manipulate singleton classes like any other > class ? > > (btw, I'm posting that because I had to implement my own ancestors-like > method ...) I can't speak for matz, but I have heard a number of reasons this is currently so: 1) Matz has stated that the way singleton classes might change. Details are sketchy but I think it at least means we are trying to keep Ruby's options open. 2) You could think of all objects already having a singleton class (not from the implementation perspective). Yet, we don't want to force the implementation to create such a class when ancestors is called. 3) It seems easy enough to create a specific accessor since all objects (except a few) are subject to this: class Object def singleton_class class << self; self end end end Of course, that might seem like a gross abuse to some and a wonderful tool to others. I'm not really moved one direction or another. I can say that I enjoy the utility of being able to easily access the singleton class. Brian.