#!/usr/bin/env ruby # This code comes from http://ruby-it.org/pages/Mixin # Check the page for copyright notice and explanations module M def foo "foo!" end end class C include M end C.new.foo #=> "foo!" >> module Vendibile >> def stringa_prezzo >> prezzo.to_s+" euro" >> end >> def prezzo_ivato >> prezzo+ (prezzo*20)/100 >> end >> def to_s >> self.class.inspect+": "+stringa_prezzo >> end >> end => nil >> class Lampada >> include Vendibile >> def prezzo() 100 end >> end => nil >> l=Lampada.new => Lampada: 100 euro >> l.prezzo_ivato => 120