From: Christoph (news_chr) Date: 2003-10-03T15:50:27+09:00 Subject: Re: mixing in class methods "Mark J. Reed" wrote: .... > > Thanks to all. The :append_features solution was giving me trouble > with modules that included other modules; :included may help there. On a serious note: The following might give you an idea on dealing with the ``include Modules in other Module'' issue. ---- class MModule < Module # the name is arbitrary def initialize @class_module = Module.new super end private def class_methods(&b) @class_module.module_eval &b end def included(mod) if mod.is_a? Class mod.extend @class_module else mod.is_a? MModule mod.class_module.__send__(:include,@class_module) end end protected attr_reader :class_module end # usage # M = MModule.new do def instance_method1 p "instance_method1" end class_methods do def class_method1 p "class_method1" end end end # a MModule constant can be used like regular Module constant module M def instance_method2 p "instance_method2" end class_methods do def class_method2 p "class_method2" end end end # include example N = MModule.new do include M def instance_method3 p "instance_method1" end class_methods do def class_method3 p "class_method3" end end end class C include N end C.new.instance_method1 # instance_method1 C.new.instance_method2 # instance_method2 C.new.instance_method3 # instance_method3 C.class_method1 # class_method1 C.class_method2 # class_method2 C.class_method3 # class_method3 ---- /Christoph