Trans
9/27/2006 1:23:00 PM
dblack@wobblini.net wrote:
> Hi --
>
> On Wed, 27 Sep 2006, Vincent Fourmond wrote:
>
> >
> > Hello !
> >
> >> Not too long ago this was discussed with a length with Matz. The result
> >> was #class_extension.
> >>
> >> module Base
> >> def desc
> >> return self.class.desc
> >> end
> >>
> >> class_extension do
> >> def desc
> >> return @desc
> >> end
> >> end
> >> end
> >>
> >> class ThisClass
> >> include Base
> >> end
> >>
> >> An excellent pure Ruby implementation of this was developed by Daniel
> >> Schierbeck, It can be found it the Facets project
> >> (facets.rubyforge.org). To use: require 'facet/module/class_extension'.
> >> For convenience the code follows.
> >
> > Thanks !
> >
> >> It remains to be seen if Matz ultimately goes with this approach in
> >> Ruby 2.0. But as of yet I guess one could say it the most "official"
> >> technique available. (Not to say that others are prefectly valid of
> >> course)
> >
> > That would be cool if the syntax could be somewhat lighter: it somehow
> > doesn't look right to me to have the code within a block. But that's
> > just aesthetics... And that would be for ruby 2.0, if I understand right.
>
> I agree; it seems odd to resort to a block when generally the
> inclusion/extension mechanism involves modules.
Yea. I get the same vibe. There's no precedence for it so it doesn't
seem very Rubyish. But at the very least I'm happy to have something
that works well. Also it doesn't require any changes under the hood so
I imagine it'll just be part of the standard library, nor core. Ideally
though I still tend to favor an alternate to #include, eg
#include_with_class_extension, or something (though that name is way
too long). But a solution like that does require some changes to Ruby
itself --it's not possible to implement in plain Ruby.
> Also, the terminology
> is a bit narrow; it should really be 'includer_extension' or
> something, since modules can be included by modules as well as
> classes.
I think "class" is referring to the singleton, which is a class in
etither case.
T.