I have a Ruby class into which I want to include both class and instance methods. Following the pattern described in "Ruby Pattern: Extend through Include", I'm currently using the following:
class SomeObject include SomeObject::Ability def self.some_builder_method(params) # use some_class_method ... end end module SomeObject::Ability module ClassMethods def some_class_method(param) # ... end end def self.included(klass) klass.extend(ClassMethods) end def some_instance_method # ... end end
I'd rather not make two separate modules, one being included and the other being extended, because all the methods in my module logically fit together. On the other hand, this pattern requires me to:
- Define an additional
- Write a boilerplate
self.includedmethod for every module.
Is this the most idiomatic way to approach this?