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

Scott Taylor mailing_lists at railsnewbie.com
Tue Nov 25 13:16:42 EST 2008

On Nov 25, 2008, at 1:14 PM, Mark Wilden wrote:

> On Tue, Nov 25, 2008 at 10:04 AM, Matt Wynne <matt at mattwynne.net>  
> wrote:
> On 25 Nov 2008, at 17:54, Mark Wilden wrote:
> On Tue, Nov 25, 2008 at 8:54 AM, Matt Wynne <matt at mattwynne.net>  
> wrote:
> Surely, as soon as they scroll off the screen, it's time to factor  
> that code off into a module or class of its own though?
> That's assuming there are a lot of class methods. There might be  
> only one, but if that 'class << self' is off the screen, there's the  
> potential for confusion (among noobs and gurus alike). In many if  
> not most cases I've seen, there were no counterbalancing benefits.
> I don't understand. If it's off the screen, it's off the screen,  
> whether it's defined using self.foo or class << self; def foo; end;
> If the def line is off the screen, then you don't even know what  
> method you're in (at least with most editors). I wasn't talking  
> about that.
> Look, all I'm saying is that to understand the meaning of a chunk of  
> code, you need to see more lines with 'class << self' that without  
> it. Personally, I like relatively terse code, because it's easier to  
> read - if for no other reason than that more fits on a single screen  
> without losing clarity.
> I'd be interested, however, in hearing about the benefits of opening  
> the eigenclass to define class methods (apart from ease in  
> searching, which may be best handled with ctags).

Grouping and private methods.

You won't risk having a class methods scattered all over the file.


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/rspec-users/attachments/20081125/4b45d150/attachment.html>

More information about the rspec-users mailing list