From: Gregory Seidman Date: 2006-06-12T04:33:46+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? On Mon, Jun 12, 2006 at 03:48:14AM +0900, Daniel Schierbeck wrote: [...] } What I like about my solution is the interface -- the implementation was } something I just jotted down. This would of course be better (feel free } to point out any errors): } } class Module } def class_methods(&block) } @class_methods ||= Module.new } @class_methods.module_eval(&block) } end } } def included(mod) } mod.extend(@class_methods) } end } end } } That way you don't need to have a constant (which clutters the namespace.) That has two problems. First off, if you don't call class_methods before you first include the module (e.g. you want to reopen the module later to add class methods), the included method will fail since @class_methods is nil. Also, including the module in another module will not behave as expected. See http://redcorundum.blogspot.com/2006/06/mixing-in-class-methods.html for code and an explanation. It's similar to what you have, except: - a little more bulletproof - manages inclusion in modules gracefully - requires an explicit directive to provide the class method mixin functionality - provides a hook to put code in included() } Cheers, } Daniel --Greg