From: "David A. Black" Date: 2004-08-11T09:02:43+09:00 Subject: Re: Singleton class methods Hi -- On Wed, 11 Aug 2004, Gennady wrote: > David A. Black wrote: > > > Hi -- > > > > On Wed, 11 Aug 2004, Gennady wrote: > > > > > >>>>At least for "def Foo.f1" and "class << Foo" it is not the same one: one > >>>>holds "A=10" and another -- "A=20". > >>> > >>> > >>>But only one of them is a singleton class; the other is simply Foo > >>>itself :-) When you do def Foo.m, 'self' is Foo; but when you do class > >> > >>That's where a slight misunderstanding might have occurred: I was > >>calling "Foo itself" an original singleton class (isn't it? ;-)), and > >>the one created by "class << Foo" -- an anonymous singleton class of Foo > >>(i omitted word "anonymous" from my original reply, sorry). > > > > > > I realize that we should probably be saying 'virtual class' instead of > > 'singleton class' (at least, that's what shows up in the error > > messages when you try to instantiate one) -- but either way, Foo isn't > > one :-) It's just a regular class. > > > > > > David > > > Hmm, I like "virtual class" much better. I used term "singleton" for > describing Foo's class simply to reflect that there's only one instance > of class "Class" representing "Foo". Seems like my terminology was > misleading. It's not a very useful usage -- you'd have to call every object in Ruby a 'singleton' then :-) 'Singleton class' has always had the problem that there's also the Singleton module, so 'singleton class' can also mean a class that includes that module. 'Virtual class' strikes me as possibly causing confusion, or false expectations, due to the use of that term for very different things in other languages. But I don't have a perfect term for it by any means. (I think there was a discussion about this on ruby-core or somewhere lately... couldn't find it in a quick search.) David -- David A. Black dblack@wobblini.net