From: Daniel Schierbeck Date: 2006-06-15T23:38:24+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? transfire@gmail.com wrote: > I assume you are doing this for the challenge / learning expience.... That, and it's nice to have an implementation that fits with the interface we have pretty much agreed on (well, matz has). > #included is not the best method to use since it is a callback. While > you could override #include itself, probably the most appropriate > method to use is #append_features. This is the method include calls to > do it's "magic". > > Also, after defining the class_extension method for Module, you'll want > to undefine it for Class, since it has no relevance there: > > class Class > undef_method :class_extension > end Thanks for the feedback, here's the updated version. class Module def class_extension(&block) @class_extension ||= Module.new do def self.append_features(mod); end end @class_extension.module_eval(&block) if block_given? @class_extension end def append_features(mod) mod.extend(class_extension) if mod.instance_of? Module and mod.respond_to? :class_extension mod.send(:class_extension).send(:include, class_extension) end end end class Class undef_method :class_extension end #class_extension should probably be private, right? Daniel