Hi --

On Wed, 11 Aug 2004, Gennady wrote:

> Kyle Putnam wrote:
> > Hello,
> > 
> > It seems these two syntaxes accomplish the same thing, or are there
> > differences?
> > 
> >     class Foo
> >         class << self
> >             def bar
> >                 # ...
> >             end
> >         end
> >     end
> > 
> > compared to...
> > 
> >     class Foo
> >         def Foo.bar
> >             # ...
> >         end
> >     end
> > 
> > Cheers,
> >     Kyle
> > 
> > 
> 
> Exactly the same from the functionality point of view (it differs in 
> implementation, though). I personally prefer the first form, as when it 
> comes to renaming a class, you can do it in one place. Also with this 
> form you can do other nice things such as defining class attribute 
> accessors with attr_reader, attr_writer or attr_accessor.

One difference (I believe this was pointed out to me once by Guy
Decoux, in response to the same question) is the scope of constants.
If you open the new scope with << self, constants visible in method
definitions will be those of that singleton class, rather than those
of the original class.


David

-- 
David A. Black
dblack / wobblini.net