From: Peter Cooper Date: 2007-06-12T20:18:20+09:00 Subject: Re: self in method name On 6/12/07, Bertram Scharpf wrote: > > class Foo > > def self.bar > > ... > > end > > end > > Is this the same thing as > > class Foo > class < def bar > ... > end > end > end Yes, except in the second you're actually opening up the virtual class to work on it directly whereas in the first example you're defining the method using an absolute name. It's easy to see this as a pattern though without understanding the background, which, hopefully, a brief example will rectify: class << Fixnum def x; "y"; end end puts Fixnum.x # => "y" puts 10.x # ERROR Note that you can dig into virtual classes at any time, not just within the capacity of a class you're currently defining :) So.. when you see class << self within the definition of another class, then it's the equivalent of class << ClassName, and merely using the "self" to provide the current class rather than naming it explicitly. Cheers, Peter Cooper http://www.rubyinside.com/