On Fri, Dec 3, 2010 at 5:05 AM, Gary Wright <gwtmp01 / mac.com> wrote:
> On Dec 2, 2010, at 6:59 PM, Tony Arcieri wrote:
>> On Thu, Dec 2, 2010 at 4:55 PM, Gary Wright <gwtmp01 / mac.com> wrote:
...
>> Earlier I asked how this was implemented... apparently "class objects" have
>> instance-specific behavior in their "singleton class" which takes the form
>> of "singleton methods"?
>
> Yes, but this is not special behavior for class objects.
>
> Per-object behavior in Ruby is implemented by adding methods to the singleton
> class for the object. It doesn't matter if the object is a string, an array,
> or a class. The per-object methods (i.e. singleton methods) are allimplemented
> in the same way, via instance methods of the singleton class for the object.
>
> If the object happens to be a class object then those singleton methods are
> commonly known as 'class methods' but that is just a naming convention.

For me, it was the book "Advanced Rails" by Brad Ediger (O'Reilly) that finally
got me to understand how this really fits together. Already on page 12 to 15,
you get an excellent explanation over why it works the way it does (and it's
brilliant in it's simplicity, once you get it :-)

Peter