ActiveSupport provides a pretty idiomatic and cool way of doing that, ActiveSupport::Concern
:
module Whatever
extend ActiveSupport::Concern
module ClassMethods
def say_hello_to(to)
puts "Hello #{to}"
end
end
end
class YourModel
include Whatever
say_hello_to "someone"
end
See the API doc. Although it is not directly related to your question, the included
method is incredibly useful for models or controllers (scopes, helper methods, filters, etc), plus ActiveSupport::Concern
handles dependencies between modules for free (both as in freedom and as in beer).