From: Joel VanderWerf Date: 2006-06-10T03:37:29+09:00 Subject: Re: Why the lack of mixing-in support for Class methods? ara.t.howard@noaa.gov wrote: ... > plus, the first case is annoying. if it weren't, people wouldn't be > rolling > their own shortcuts left and right - which is kind of what this thread is > about. Here's another shortcut, dunno how original it is. I don't like the #import (or #include!) suggestions because they take control away from the module. In most cases, the module will know best which (if any) class methods to contribute. class Module def included_class_methods(&bl) if bl included_class_methods_module.module_eval(&bl) else included_class_methods_module.instance_methods end end def included(cl) cl.extend included_class_methods_module end private def included_class_methods_module @included_class_methods_module ||= Module.new end end module M included_class_methods do def bar; "BAR"; end end def self.zap; "ZAP"; end def foo; "FOO"; end end class C include M p bar begin zap rescue puts "Can't call C.zap" end end p C.new.foo p M.included_class_methods __END__ Output: "BAR" Can't call C.zap "FOO" ["bar"] -- vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407