From: Logan Capaldo Date: 2006-03-01T11:38:05+09:00 Subject: Re: Dynamic stuff and books --Apple-Mail-10--360199320 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed On Feb 28, 2006, at 8:03 AM, Ross Bamford wrote: > 'class' here is doing what you expect it to do - defining a class. But > the class that's being defined is a singleton class belonging to the > object on the rhs of the <<. Basically, objects in ruby can have two > classes - the class of which they are an instance, and a singleton > class > that relates to (and supplies methods for) just that object. This > syntax > is for use with the latter. Well actually it still has only one class. What happens is it injects the Singleton class into the inheritance hierarchy of the object before it's original class. sort of like this (In not valid ruby): a = "hello" class SingletonClassForA < String def a_method self << " world" end end a.change_class(SingletonClassForA) a.a_method puts a "hello world" --Apple-Mail-10--360199320--