From: William Rutiser Date: 2010-12-06T23:35:45+09:00 Subject: Re: Singleton class, metaclass, eigenclass: what do they mean? Rick DeNatale wrote: [snip] > As an aside, which is probably more apropos the title of this thread. > I don't personally consider singleton_class, eigenclass, and metaclass > to be equivalent terms. > > In particular I reserved the term metaclass to be the 'singleton' > class of a class object. I put singleton in quotes here because, > although MRI uses the singleton class mechanism to implement > metaclasses, metaclasses are 'less' singleton when you consider that > 'singleton' methods which are found in the mtab of the object's > singleton class, are not shared by any other object, class methods > which found in the mtab of the metaclass ARE shared in the case where > the class in question has one or more subclasses. > > The etymology of the word metaclass is similar to that of metalanguage > > meta- (also met- before a vowel or h) > combining form > 1 denoting a change of position or condition : metamorphosis | metathesis. > 2 denoting position behind, after, or beyond: : metacarpus. > 3 denoting something of a higher or second-order kind : metalanguage | metonym. > > i.e. the third definition of meta here. > > and > > metalanguage |��met����la ng (g)wij| > noun > a form of language or set of terms used for the description or > analysis of another language. Compare with object language (sense 1). > ��� Logic a system of propositions about propositions. > > So as I define it (and as is normal in most OO languages) a metaclass > is a form of class used to describe a class. A singleton class used > to describe singleton methods of an object is NOT a metaclass but > rather a singleton CLASS for that object, which inherits from the > objects original class, and is hidden from Ruby's reflection methods > because that 'virtual' bit is set. > > IMHO, _why sowed a seed of confusion when he used metaclass in a way > which conflicts with the common definition, in the poignant guide. > > > >> * Note 1: If I understand correctly, for an object that is not >> a class, the singleton_class is not prepared a priori, but >> is generated at the time when it is called. >> > > This is true, although it's really an implementation detail. I don't > think you can detect this from Ruby without the aid of a C extension > to let you look for a singleton class without having one created > automatically as soon as you ask for it with, say class << > self;self;end > > I suppose I should really turn this into a blog article. > > Is the word "singleton" used widely or at all in this sense in connection with languages other than Ruby? I don't recall encountering this use except for Ruby. Do I understand that the non-existence of a singleton_class until needed is just an implementation alternative to always having a possibly empty singleton_class? I am looking forward to a blog article.