From: transfire@... Date: 2006-06-15T21:47:02+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? Daniel Schierbeck wrote: > Simplification. Tell me if I should stop spamming. > > class Module > def class_extension(&block) > @class_extension ||= Module.new do > def self.included(mod); end > end > @class_extension.module_eval(&block) if block_given? > @class_extension > end > > def included(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 > > The code might need a change if we decide to make #class_extension private. Daniel, I assume you are doing this for the challenge / learning expience.... #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 HTH, T.