[rspec-users] class << self considered harmful... really?

Matt Wynne matt at mattwynne.net
Wed Nov 26 09:51:28 EST 2008

On 26 Nov 2008, at 14:38, Peter Jaros wrote:

> On Wed, Nov 26, 2008 at 8:23 AM, Shot (Piotr Szotkowski)  
> <shot at hot.pl> wrote:
>> If you don't use class << self, you have to work on class variables  
>> and
>> you can't use the attr_* shorthands to access the singleton's  
>> variables.
> Actually, instance variables in a "def self.*" method still refer to
> the singleton object.  The body of that method is treated just like a
> method in "class << self".  You just don't get a chance, as you say,
> to make accessors with "attr_*", since that goes outside your method
> definitions.
> Peter

That's one of the things that attracted me to using class << self to  
contain all these methods - it just seemed easier to me to visualise  
what was going on.

I'd be really interested to know the nature of the criticisms made  
about it in the Matz book Mark mentioned.


More information about the rspec-users mailing list