Module

Mixin

module AnyModule
  def any_method
    "method defines in module"
  end
end

class AnyClass
  include AnyModule

  def any_method
    "method defines in class"
  end
end

class AnotherClass
  include AnyModule
end

obj = AnyClass.new
puts obj.any_method
#=> method defines in class

obj2 = AnotherClass.new
puts obj2.any_method
#=> method defines in module

Reference

results matching ""

    No results matching ""