From: "David A. Black" Date: 2004-09-14T19:42:45+09:00 Subject: Re: Singleton method on object via define_method? Hi -- On Tue, 14 Sep 2004, Robert Klemme wrote: > > [I wrote:] > > > > I think we're looking at this backwards in this discussion. We're > > looking at it as: Objects have this weird class-like thing, so what > > is it? I think it's better to look at it from the other end, like > > this: Objects in Ruby can have methods added to them on a per-object > > basis. That's a fundamental principle of Ruby (whether it is true of > > other OO languages or not). The way Matz has chosen to implement this > > is by associating a second, dedicated class with each object. That's > > what this class actually *is* -- it's the fulfillment of that design, > > not something growing off the design that has to be explained > > separately. > > While that's certainly true, we're (I am) here trying to grasp the nature > of these things to come up with a more appropriate name. At least that's > my understanding of the thread. I agree, but I think the nature of singleton (or whatever) classes is that they serve to manifest an important design feature of Ruby. That being their nature, questions like whether they are identical to other classes, etc., are secondary, not primary. > > -- it's just a matter of efficiency, and it's > > transparent. And it's a perfectly real class, because it fits the > > definition of what a class can be in Ruby. > > .... apart from the instance creation. But that's the point: "being a class" in Ruby does not actually always mean being instantiable. We know this, because there are classes that aren't. To argue it the other way would be like saying: there are variables that begin with "@", so variables in Ruby begin with "@"; therefore, "var" can't be a variable. (Don't worry -- I'm completely aware of what can be said both for and against this analogy :-) But I still think it's good to let the language talk to us, rather than the other way around.) > > Hmmm... "dedicated_class"... hmmm... :-) > > How about "instance_class"? Interesting... though kind of weird that an object would be an instance of something other than its instance_class :-) David -- David A. Black dblack@wobblini.net