From: Rick DeNatale Date: 2009-12-11T22:49:39+09:00 Subject: Re: solve this ruby problem On Fri, Dec 11, 2009 at 6:38 AM, Howard Roberts wrote: > I can tell you this: > > (pretty much) Everything in Ruby is a class No my friend, most things in Ruby are not classes, (pretty much) everything in Ruby is an object, and objects have classes, some objects have singleton classes, which give them extra methods or override methods they would have otherwise gotten from their class and its parents (superclasses). Classes, themselves, being objects have a class called Class, and all have a singleton class which gives them additional methods (class methods) which are in addition to or override methods provided by Class. There's at least one subtle difference, relating to the meaning of singleton, between singleton classes of ordinary objects and singleton classes of classes. Methods defined in the singleton class of an ordinary object only apply to that individual object instance, whereas methods defined in the singleton class of a class are available to that class and any of its subclasses. The difference is that in the first case the superclass field of the singleton class refers to the object's class, while in the latter it refers to the singleton class of the class's superclass. So while some consider class methods to be 'singleton methods' of the class, a case can be made that this isn't really true, particularly if the class has any subclasses, because the class methods apply to more than a single object. -- Rick DeNatale Blog: http://talklikeaduck.denhaven2.com/ Twitter: http://twitter.com/RickDeNatale WWR: http://www.workingwithrails.com/person/9021-rick-denatale LinkedIn: http://www.linkedin.com/in/rickdenatale