On Sat, Jan 31, 2009 at 8:03 PM, Thomas Sawyer <transfire / gmail.com> wrote:
[snip]
> Consider this form in place of the usual 'class << self':
>
>  class X
>    extend Module.new {
>      ...
>    }
>  end
>
> Not quite as elegant since we can't use do...end. But if #extend could
> take a block:
>
>  class X
>    extend do
>      ...
>    end
>  end
>
> Then the issue becomes transparent. Even for regular objects:
>
>  obj.extend do
>    ...
>  end
>

I like this - how do you see it working alongside the proposed
#class_extension from a while ago?

I guess #extend would work as above (i.e. defines singleton methods on
instances), where #class_extension (or #class_extend?) methods/modules
would both extend a class and be inherited by subclasses. I forget
where the discussions on module inheritance ended up. Would you have a
#module_extend method too or would #class_extension work for both
classes and modules (in which case it should be renamed or alased)?

> This is not to say that a singleton_class/eigenclass method would never
> be of use, but it would certainly mitigate the need for it a great deal.
> (One might also take away from this that a better name for it, if it
> were given a method name, would be #extension, but I mention that only
> as an aside.)

I think you're onto something here - conceptually, #extend, singleton
methods and the-class-that-cannot-be-named are closely related but you
wouldn't know that from their names (or lack of them).

Perhaps #extension_class?

Regards,
Sean