[Regarding the term "metaclass"] > On Mon, 18 Apr 2005, why the lucky stiff wrote: > > I only use the term "metaclass" because it is the term predominantly used > > in the PickAxe II. While Dave does interchangibly use "virtual class" > > and "singleton class", the only term he uses to generically refer to the > > construct is "metaclass". On Monday 18 April 2005 03:55 pm, David A. Black wrote: > I read the Pickaxe differently, especially the box on p. 382. It > paraphrases Matz as having said: "You can call it _metaclass_ but, > unlike Smalltalk, it's not a class of a class; it's a singleton class > of a class." I don't have the pickaxe with me (its at work), but let me quote from "Putting Metaclasses to Work" by Ira R. Forman and Scott H. Danforth. The quote is longish, but useful in understanding metaclasses. From the Preface: > "If one thinks of objects as cookies, then classes are analogous to cookie > cutters. Cookie cutters are teamplates that are used to make and determine > the properties of cookies; classes make and determine the properties of > objects. But ow are cookie cutters themselvfes made? Let us ssay that they > are pressed from sheet metal using a cookie cutter press (a piece of heavy > machinery). So, if a cookie cutter press is ed to make cookie cutters, what > is used to make classes? The answer is a metaclass." So, the instances of a metaclass are classes. Ruby happens to implement metaclasses as singleton classes (or virtual classes, whatever). So the singleton class of a class is a metaclass, but the singleton class of something that is not a class, would not be a meta class. I would modify Why's metaid library thusly: class Object def singletonclass class << self self end end end class Class def metaclass singletonclass end end Allowing ... >> o = Object.new => #<Object:0x40253228> >> Object.metaclass => #<Class:Object> >> o.metaclass NoMethodError: undefined method `metaclass' for #<Object:0x40253228> from (irb):4 >> o.singletonclass => #<Class:#<Object:0x40253228>> >> Object.metaclass == Object.singletonclass => true > (I think I misread the p. 382 thing about "virtual". It does actually > sound like Matz is accepting it as a synonym for "singleton", though I > avoid it because I don't see anything "virtual" about singleton > classes. They're objects.) I think the "virtual" is a modifier of "class", not "object". A virtual class is something that is like a class in someways (it holds instance methods), but unlike a class in other ways (can't create new instances of it). -- -- Jim Weirich jim / weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)