From: dblack@... Date: 2006-09-27T19:15:44+09:00 Subject: Re: Modules, instance methods and class methods 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. 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. David -- David A. Black | dblack@wobblini.net Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB's Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org