From: James Edward Gray II Date: 2006-06-12T01:09:07+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? On Jun 11, 2006, at 10:40 AM, Daniel Schierbeck wrote: > James Edward Gray II wrote: >> Here's another idea: >> >> class Module >> >> def included(receiver) >> >> receiver.extend(const_get(:ClassMethods)) if >> const_defined? :ClassMethods >> >> end >> >> end >> => nil >> >> module Test >> >> module ClassMethods >> >> def test >> >> "I'm a class method." >> >> end >> >> end >> >> def test >> >> "I'm an instance method." >> >> end >> >> end >> => nil >> >> class MyTest >> >> include Test >> >> end > > I'm not too fond of the nested module approach -- I think it's > cleaner to use a method. But that's a matter of opinion, of course. Oh well, to each their own. I prefer the nested module approach because: 1. I can envision the threads here where we try to explain when to define class methods with and without the method. 2. It has a been a common Ruby idiom for literally years, so history works in our favor. James Edward Gray II