From: Christoph Schiessl Date: 2008-05-18T07:39:21+09:00 Subject: Re: Class methods in modules Interesting - so class methods in modules don't make any sense at all? Calling the modules class methods directly and special class methods such as included(base) and extended(base) are the exception of course. Would you agree with that statement (question to everyone)? On May 17, 2008, at 12:35 AM, Rick DeNatale wrote: > On Fri, May 16, 2008 at 3:36 PM, Florian Gilcher > wrote: > >> If you wish to keep class an instance methods separated, it is >> somewhat >> popular >> to define them in different modules: >> >> module FormatHelper >> module ClassMethods >> def foo >> ##### >> end >> >> #some more methods >> end >> >> module InstanceMethods >> def foo >> ##### >> end >> >> #some more methods >> end >> end >> >> class D >> include FormatHelper::InstanceMethods >> extend FormatHelper::ClassMethods >> end > > Or for a module, which adds both class and instance methods, the > popular way is something like this: > > module FormatHelper > > def self.included(class_or_module) > class_or_module.extend(ClassMethods) > end > > module ClassMethods > ... class methods go here > end > > .. instance methods go here > end > > Then when a class includes the module it gets both sets of methods. > > -- > Rick DeNatale > > My blog on Ruby > http://talklikeaduck.denhaven2.com/