From: Chris Pine Date: 2005-04-20T23:29:48+09:00 Subject: Re: [ANN] Article: Seeing Metaclasses Clearly > > One possible explanation for this discrepancy is that the diagram is wrong. > > Another is that instance_of? doesn't take into account singleton classes. > > > > I guess it's the second one :). > > instance_of? tells you (accurately, definitively) whether or not > something is an instance of something. Obviously you can draw a > diagram that posits any relationship you wish. Then what do the sideways arrows in the 'ri Class' documentation mean? Carlos didn't draw that diagram, and he isn't making that up. Clearly, there's a meaningful relationship there. See again the 'klass' arrow on page 384 (Figure 24.3) of the Pickaxe2. If "instance_of? tells you (accurately, definitively) whether or not something is an instance of something", then it sounds like you defining the instance of something to be "that which is returned by instance_of?". It seems to me that there are two very different relationships here: what I will call "instance" (though David might not like how I will use it) and what I will call "superclass". These are the arrows used both in 'ri Class' and in the pickaxe, and I think these are the meaningful relationships. (Usually, the relationship one-to-many relationship of 'kind_of?' is what we want, but that is built out of one "instance" relationship, and zero-or-more "superclass" relationships.) When you create a singleton class for an object, you are changing the 'klass' pointer and, as I see it, changing which class it is an instance of. What is returned by "instance_of?" does not change (and I'm complaining about that, mind you; I'm fine with how it works), but that object's immediate "papa" has changed. I would also argue (I mean, it's almost the same statement) that the objects class has changed, despite the fact that method 'class' still returns the original class. I think that's what Carlos is saying, and I think he's right. (And if that's not what he's saying, then... um... I think *I'm* right! :) I thought that the reason these methods didn't reflect the singleton-ness under the skin of Ruby was that matz didn't want us mucking around there. As I recall, he thought of it as an implementation, but that he might want to change that some day. (I think it's more of a necessity of the language than an implementation detail, personally. When I saw that (Object)'s superclass was Class, my mind was opened. :) Chris