Hi --

On Mon, 2 Feb 2009, Thomas Sawyer wrote:

> David A. Black wrote:
>> I wouldn't want to see 'extend' start to mean both adding a module to
>> the lookup path, and adding methods to the singleton class, depending
>> on the context. I guess obj.extend do ... could create an anonymous
>> module, though I've never had an issue with just creating it with
>> Module.new or using a named module.
>
> Ah, sorry I wasn't more clear. Yes, I meant it would create an anonymous
> module, so as to promote good coding practices. And I agree, it isn't
> that hard to use Module.new or name the module, nevertheless we see the
> singleton being used directly far too often b/c it is more convenient,
> even when having to define our own #singleton_method. And that's the
> point of the suggestion, to make it more convenient to #extend rather
> than #class_eval on the singleton class. Indeed (I wish I could find
> that article) one can make a good case that the singleton class should
> never have methods directly defined in it; always use a module.

I'd be interested in seeing that article if you can find it. It
doesn't strike me right off as a convincing idea, but the reasoning
would be interesting to see.


David

-- 
David A. Black / Ruby Power and Light, LLC
Ruby/Rails consulting & training: http://www.rubypal.com
Coming in 2009: The Well-Grounded Rubyist (http://manning.com/black2)

http://www.wishsight.com => Independent, social wishlist management!