On Tue, Nov 25, 2008 at 5:41 AM, Matt Wynne <[EMAIL PROTECTED]> wrote:

> Sorry, I know this is off-topic, but I'd really like to know what the
> revered ruby-hackers who read this list think.
>
> See
> http://ozmm.org/posts/class__self_is_harmful.html
>
> I have adopted class << self, partly from reading RSpec and Cucumber's code
> as I learn Ruby. I personally think of class methods (or 'static' methods)
> as being in a kind of 'holding pen' waiting to be factored off onto a proper
> class of their own, so I rather like the clear way you can group them in a
> 'nameless' metaclass ready for the exit door.
>

The nature of class methods in Ruby (as instance methods of the class's
eigenclass) is for most purposes an implementation detail. It adds nothing
to understanding to open the eigenclass inside the class's definition in
order to add class methods. It may save some typing, and it does help when
searching (as David) says. Nevertheless, I regard the practice as a bit of
an affection - 'look at me, ma, I'm opening the eigenclass!' - or as the
imitation of an affection. It confuses newbies to no purpose, and confuses
everyone when 'class << self' has scrolled off the top of the screen.

It's recommended against in The Ruby Programming Language (of course, there
are exceptions to every rule).

///
_______________________________________________
rspec-users mailing list
rspec-users@rubyforge.org
http://rubyforge.org/mailman/listinfo/rspec-users

Reply via email to