On Tue, Sep 09, 2003 at 12:54:01PM -0700, John wrote:
> My question is, in what case would you use
> 
> class TheClass
>   class << self
>     def foo
> 
> Couldn't you just say
> 
> class TheClass
>   def foo

No; that would define an *instance* method called 'foo'.
The first example defines a *class* method called 'foo'.  

That is, in the first example, you would call it like this:

	TheClass.foo

And within the method, 'self' would refer to TheClass.

In your version, TheClass.foo doesn't exist; instead, you
have to instantiate the class and call foo on the object:

	obj = TheClass.new
	obj.foo

And within the method, 'self' will refer to obj.

Instead of using the class << self notation, you could do this:

	class TheClass
	    def TheClass::foo

But that can get tedious when defining multiple class methods,
plus you run the risk of missing a change if you rename the class
later.

-Mark