From: "David A. Black" Date: 2005-04-21T06:57:51+09:00 Subject: Re: Question on Singleton Classes (was: Seeing Metaclasses Clearly) Hi -- On Thu, 21 Apr 2005, Jim Weirich wrote: > > David A. Black said: > >> On the other hand (also from the point of view of a chronic >> explainer of Ruby :-) it's easier to say: Every object has a birth >> class and a singleton [or whatever] class, than: Every object has a >> class and a (class << self; self; end) :-) > > A question for those familiar with Ruby internals ... does an object's > singleton class exist from the moment the object is created, or does it > spring into existence the moment it is needed to hold singleton methods? I'm pretty sure it springs into existence for the purpose, just to avoid overpopulating object space with classes. Otherwise there would be, say, 10000 class objects created for an array of 10000 one-byte strings, etc. (This is based partly on some familiarity with internals and also memory of previous discussions with people with more familiarity with internals.) David -- David A. Black dblack@wobblini.net