From: "David A. Black" Date: 2008-09-30T19:23:11+09:00 Subject: Re: extend keyword in class definition Hi -- On Tue, 30 Sep 2008, ruud grosmann wrote: >> It's neither. extend() is method that all objects have (classes are objects >> too). It takes the methods from a module (in this case Forwardable) and adds >> them as singleton methods to the object. Forwardable contains the method >> 'def_delegators', which we see here has been added as a singleton method to >> WriterDecorator. >> > > thank you for your replies. But I'm afraid that I need some more > explanation. Isn't a singleton method a method that applies to the > singleton class of one object? And in this case we're talking about a > class, not an object? > > As such, Forwardable is mixed in, is my first thought. What have I > understood wrongly? Classes *are* objects. c = Class.new # c is an object whose class is Class c.extend(SomeModule) Every class is an instance of the class Class, so you can extend classes just like other objects. I've always said that the answer to 75% of all questions about Ruby is: Classes are objects :-) It's definitely a very key thing. David -- Rails training from David A. Black and Ruby Power and Light: Intro to Ruby on Rails January 12-15 Fort Lauderdale, FL Advancing with Rails January 19-22 Fort Lauderdale, FL * * Co-taught with Patrick Ewing! See http://www.rubypal.com for details and updates!