On 4/15/07, eden li <eden.li / gmail.com> wrote:
> Dang, you beat me to it.  I had typed up a similar response.  Here's a
> minor tweak though.
>
> On Apr 15, 4:02 pm, "Harold Hausman" <hhaus... / gmail.com> wrote:
> > ... the class <<obj notation, which basically says "build me a new
> > class just for object obj." ...
>
> As far as I can tell, all objects (and thus all classes) already have
> this singleton class.  "class << klass; self; end" is just a way to
> get at it.

Well logically at least.  For regular objects a singleton class isn't
created until it's needed.

So:

a = "abc"
#at this point there is no singleton class for the instance of String
referenced by a
def a.foo
   "foo"
end
#at this point it does, the singleton class was created to hold the method.

Of course you can't ever see the lack of a singleton class, at least
from ruby code,  in order to do so requires an extension.

Classes get their singleton classes when they are created.

-- 
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/