From: dblack@... Date: 2006-08-26T18:52:01+09:00 Subject: Re: Support for singleton_class() (was Re: Call functions of superclass) Hi -- On Sat, 26 Aug 2006, Rick DeNatale wrote: > On 8/25/06, Trans wrote: > >> At the very least, 'singleton_class' is too long. Just 'singleton' >> would suffice. >> >> Alas, I wish we could just go back to 'metaclass'. > > It's probably my Smalltalk background, but metaclass bothers me as a > name for a singleton class which holds INSTANCE specific methods for a > non-class. > > On the other hand, metaclass fits perfectly in my mind for naming a > singleton class of a CLASS which holds the class methods for that > class. > > The fact that in the ruby implementation, both of these are singleton > classes is an accident of implementation (in the sense of accidental > being the antonym of essential). But it's very characteristic of Ruby. There are rather few special cases. Objects have singleton classes (most objects, anyway); classes are objects; therefore, classes have singleton classes. It's interesting to me how little the language cares, so to speak, whether we as its users decide to name the singleton classes of classes 'metaclasses', or the singleton methods of classes 'class methods'. We're free to do that, but at the language level the model is consistent as between classes and other objects. (Singleton classes of classes are a bit special-cased -- in the sense that they become each other's superclasses -- but for the most part, classes behave as "civilians" when it comes to the singleton mechanisms.) > Now if I might dredge up some > Smalltalk terminology, I might suggest that we call: > > The singleton class of an instance its 'behavior' and What would you then call its behavior? :-) (i.e., the way it behaves) I can't comment on the Smalltalk aspect of the terminology, but I don't think it's a good fit for Ruby singleton classes. If I have an object obj, I don't think the phrase "obj's behavior" conjures up its singleton class. > The singleton class of a class its 'metaclass.' > > Classes are about representing a 'class' of instances: instantiating > them and providing common behavior. That's the thing.... An object's 'behavior' is not uniquely determined by its singleton class, so I wouldn't want to start trying to use that word to describe the singleton class. David -- http://www.rubypowerandlight.com => Ruby/Rails training & consultancy ----> SEE SPECIAL DEAL FOR RUBY/RAILS USERS GROUPS! <----- http://dablog.rubypal.com => D[avid ]A[. ]B[lack's][ Web]log http://www.manning.com/black => book, Ruby for Rails http://www.rubycentral.org => Ruby Central, Inc.