From: Jan Svitok Date: 2006-10-18T22:19:28+09:00 Subject: Re: Mixin a module method as a class method On 10/18/06, Farrel Lifson wrote: > Is it possible to mix in a module method to become a class method? I'd > like to define the method_added method in a module and then mix it > into a class like so > module Foo > def self.method_added(method) > puts "Added #{method}" > end > end > > class Bar > include Foo > def bar > end > def baz > end > end > So that I get > Added bar > Added baz > printed out. Is there any way to do this besides making Foo a class > and subclassing Foo from it? > > Farrel See previous thread: 'Ruby for Rails p.462-464 - why include vs. extend?' or api.rubyon rails and there *::*::ClassMethods basicly something like this: module A module M module ClassMethods def some_method #... end def included(c) c.extend(ClassMethods) end end end and then a class later that does this: class B include A::M end