Ruby: Is it possible to define a class method in a module?

Yep

module Foo
  def self.included(base)
    base.extend(ClassMethods)
  end
  module ClassMethods
    def some_method
      # stuff
    end
  end
end

One possible note I should add – if the module is going to be ALL class methods – better off just using extend ModuleName in the Model and defining the methods directly in the module instead – rather than having a ClassMethods module inside the Module, a la

 module ModuleName
   def foo
     # stuff
   end
 end

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)