On Mon, 12 Jun 2006, Yukihiro Matsumoto wrote: > Hi, > > In message "Re: Why the lack of mixing-in support for Class methods?" > on Mon, 12 Jun 2006 13:37:25 +0900, transfire / gmail.com writes: > > |I guess what I don't understand is this: If I can manully separate the > |"class-level" into it's own module and resuse that, why can't I just > |reusue the class-level to begin with? > > Because it makes thing more complex, I guess. Mere #include should > not inherit class/module-level methods, since there are cases like > Math module. So we need to prepare two different method for module > inclusion instead of one, if we reuse class-level. what did you think about my solution matz? it's solves the issue cleanly and is leverages existing practices. here it is again: harp:~ > cat inheritable.rb module Inheritable Inherit = lambda do |this, other| cm = this.const_get 'ClassMethods' rescue nil im = this.const_get 'InstanceMethods' rescue nil other.extend cm if cm other.module_eval{ include im if im extend RecursiveInherit } end module RecursiveInherit def included other Inherit[self, other] super end end extend RecursiveInherit end # # example # if $0 == __FILE__ module M include Inheritable module ClassMethods def foo() 42 end end end class C include M end p C.foo module A include Inheritable module ClassMethods def bar() 'forty-two' end end module InstanceMethods def foobar() 42.0 end end end module B include A end class K include B end p K.bar p K.new.foobar end harp:~ > ruby inheritable.rb 42 "forty-two" 42.0 this way the module itself exports specific class methods in a deliberate fashion and no new keyword need be introduced to support it. regards. -a -- suffering increases your inner strength. also, the wishing for suffering makes the suffering disappear. - h.h. the 14th dali lama