allomov
2/20/2012 - 9:18 AM

mixin in ruby

mixin in ruby

class Parent
  def hello
    puts "hello from parent"
  end
end

module M1
  def hello
    puts "hello from module 1"
  end
end

module M2
  def hello
    puts "hello from module 2"
    super
  end
end

class Child < Parent
  include M1
  include M2

  def hello
    puts "hello from Child"
    super
  end
end

Child.new.hello