Over a million developers have joined DZone.

Inheriting Class And Instance Methods From Module To Class In Ruby

·
Here you can see how to define both instance and class method in a module in order to mix them into a class



module MyModule
 def my_instance_method
  ...
 end

 def self.included klass
   def klass.my_class_method
     ...
   end
 end
end


And usage:

class MyClass
  include MyModule

  my_class_method
  ...
  def method_that_uses_the_module
    my_instance_method
    ...
  end
end
Topics:

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}