From: Raul Parolari Date: 2007-11-17T14:36:50+09:00 Subject: Re: Composition: Build objects from other objects Thufir wrote: > > then can you make the vw_bug go "vroooooom" and so forth? What would be > the usual way to do this in ruby? When a car is instantiated, should an > engine object get passed to the initializer method? > > thanks, > > Thufir I do not like (at first view) the idea of this design; it leads to, as Konrad has correctly observed, to start the car by saying: vw_bug.engine.vroom() Should the car user know that he has to tell the car to ask the engine to rev up? Uhm.. Another take is the following; let's use a module Engine: module Engine attr_accessor :type def initialize @type = "generic engine" end def vroom puts "vroooooom" end end class Vehicle include Engine def initialize super end end class Car < Vehicle def initialize super end end vw_bug = Car.new vw_bug.vroom I am not crazy of the 'Engine' Module, but I definitely like to ask the VW to wroom, without worrying about what is inside, Raul -- Posted via http://www.ruby-forum.com/.