From: "Luca (Email)" Date: 2011-12-29T15:56:06+09:00 Subject: I: Navigating through the official Ruby documentation -----Messaggio originale----- Da: jake kaiden [mailto:jakekaiden@yahoo.com] Inviato: sabato 12 novembre 2011 16:20 A: ruby-talk ML Oggetto: Re: Navigating through the official Ruby documentation hi Fily, you can think of a module as a collection of useful methods that you can pass around (mix in) between various classes. from what i understand modules have a lot less 'overhead' than classes as well. you could write a module called 'Transmission' in which you define how to shift gears - and then mix that module into different vehicle classes that will all share the methods defined in the module... module Transmission attr_reader :gear def num_of_gears=(n) ... end def clutch ... end def shift(up_or_down) ... end def grind_gears ... end end class Car include Transmission def initialize(n) num_of_gears = (n) ... end ... end class Motorcycle include Transmission def initialize(n) num_of_gears = (n) ... end ... end bike = Motorcycle.new(5) car = Car.new(4) bike.clutch bike.shift('up') car.clutch car.shift('up') etc.... - j -- Posted via http://www.ruby-forum.com/. -- Caselle da 1GB, trasmetti allegati fino a 3GB e in piu' IMAP, POP3 e SMTP autenticato? GRATIS solo con Email.it http://www.email.it/f Sponsor: Capodanno a Riccione, Pacchetto Relax: Mezza Pensione + bagno turco + solarium + massaggio. Wifi e parcheggio gratis. 2 giorni euro 199 a persona Clicca qui: http://adv.email.it/cgi-bin/foclick.cgi?mid=11978&d=29-12