From: "David A. Black" Date: 2005-04-20T10:29:24+09:00 Subject: Re: [ANN] Article: Seeing Metaclasses Clearly Hi -- On Wed, 20 Apr 2005, Jim Weirich wrote: > > David A. Black said: >> I'd go along with "directly influenced", but not >> "determined"; that is, an object's "birth class" certainly has a role >> to play in the object's method capabilities, but is not a determinant. > > As do all the ancestors in the > >> What I got from the quotation, and your gloss on it, was that >> "metaclass" is recognized (outside of Ruby) to mean a factory for >> classes, and that therefore it could be used to refer to a Class >> object's singleton class. > > The analogy in the quote did indeed focus on the creation aspect, and I > did indeed gloss over the fact that singleton classes don't create new > instances. Perhaps the analogy was poorly suited for my point. > > What I was trying to communicate with the quote is that Metaclasses are to > classes what classes are to objects. As classes hold the behavior for > objects, metaclasses hold the behavior classes. A Metaclass is a class > whose instances are classes (or in the case of a singleton metaclass, whos > one and only instance is a class). Although... here's something interesting: irb(main):001:0> a = "" => "" irb(main):002:0> c = (class << a; self; end) => #> irb(main):003:0> a.instance_of?(c) => false irb(main):004:0> a.instance_of?(String) => true irb(main):005:0> s = class << String; self; end => # irb(main):006:0> String.instance_of?(s) => false irb(main):007:0> String.instance_of?(Class) => true I guess being an instance_of something is a unique relationship (only one class-of-which-you-are-an-instance to a customer), and having a singleton class doesn't mean you're an instance of it. That seems to reinforce the non-factory aspect of all singleton classes, in the sense that it disallows even the one "instance of" relationship that one might have expected them to claim to have. (I expected it -- I think I once knew, but had forgotten about, the above behavior.) >> I must have garbled something I said somewhere along the line; I >> definitely would never (knowingly :-) suggest that singleton classes >> are not classes. See below.... > > And just as the inability to create new instances does not disqualify > singleton classes from being classes, the inability for a singleton > metaclass does not disqualify it from being a metaclass. OK... but that, again, is where the quotation then becomes confusing, since its chief point is that a "metaclass" is, specifically, a factory for classes. If we use the word "metaclass" to mean singleton class of a class, we're definitely giving up any "cookie-cutter" analogy, and that seemed to be the whole thrust of that quotation. >> Correspondingly, if there is a "template for making cookie cutters >> themselves" (to paraphrase) in Ruby, it would be the object Class >> itself. > > Indeed, Class is the Metaclass from which all the singleton metaclasses > derive. And all other Class objects too. But then "[Mm]etaclass" becomes really kind of overloaded -- in the sense that on the one hand it is a suitable term for Class (which is truly the thing that stamps out the cookie cutters themselves), while on the other hand it gets used as a term for something which is unequivocally *not* in the cookie-cutter, meta-cookie-cutter, or factory family at all. David -- David A. Black dblack@wobblini.net