From: dblack@... Date: 2003-02-11T11:11:21+09:00 Subject: Re: Question about page 244 of the pickaxe... Hi -- On Tue, 11 Feb 2003, Chris Pine wrote: > Hello, > > I have a question about Figure 19.2, page 244 in Programming Ruby. > > The picture is explaining the following code: > > class Guitar > def Guitar.strings() > return 6 > end > def play() > ... > end > ... > end > > lucille = Guitar.new > > (Which, BTW, if `lucille' is a reference to something, I didn't get it. :) > > So, my question is in the picture. As I understand it, the above code > creates a Class object, Guitar, and also creates a singleton class for > Guitar. (Guitar is a class, but it's also an object, and any object (except > immediate ones) can have a singleton class.) > > If this is so, why is this picture so different from the one on the > following page, which describes how singleton classes work? Does a > singleton class sit inbetween the object and the class (like in Figure 19.3) > or does it set above the class (like in Figure 19.2)? What about the > singleton's super pointer? It is very different in the two figures. Is > Guitar's klass pointer really pointing to the singleton class instead of to > Class, like I thought all classes did? Every object's "klass" pointer will point to its singleton class, if it has one. I think this is consistent as between the two diagrams. In 19.2, Guitar's klass points to Guitar', and in 19.3, a's klass points to a's singleton class. Remember that the klass chain is different from the super chain -- in fact, it's only the former that all objects have, whereas only classes have superclasses. The thing-that-should-point-to-Class is not Guitar's klass pointer, but Guitar''s klass pointer: Guitar klass ---> Guitar' klass ---> Class super ---> Object' Similarly, for a (the string in 19.3): a klass ---> singleton (anonymous) klass ---> Class As for terminology, I think the book is using "metaclass" as a specialized term for "singleton class of a Class object", but I may be wrong or only partially right about that. It's sort of like using "class method" as a specialized term for "singleton method on a Class object". David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav