From: James Edward Gray II Date: 2006-06-12T00:05:47+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? On Jun 11, 2006, at 7:42 AM, Daniel Schierbeck wrote: > Yukihiro Matsumoto wrote: >> Redundancy can be removed by some kind of meta programming. > > This could do the job: 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 => MyTest >> MyTest.test => "I'm a class method." >> MyTest.new.test => "I'm an instance method." James Edward Gray II