From: Konrad Meyer Date: 2007-11-17T14:06:04+09:00 Subject: Re: Composition: Build objects from other objects --nextPart1801214.Iqxj1KZVsr Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Thufir: > has= =20 > a discussion of composition versus inheritance which I'm trying to apply= =20 > to ruby. For discussions sake, I'll use the classes discussed in the=20 > above linke: Car, Vehicle and Engine. Car inherits from Vehicle, of=20 > course. >=20 > Let's say that Engine is something like: >=20 > class Engine > attr_accessor :type >=20 >=20 > def initialize () > @type =3D "generic engine" > end >=20 > def vroom () > puts "vroooooom" > end > end >=20 > Vehicle would be something like: >=20 > class Vehicle >=20 > attr_accessor :engine >=20 > def initialize () > @engine =3D Engine.new > end > end >=20 >=20 > class Car < Vehicle >=20 > def initialize () > super() > end > end >=20 > then from IRB for instance: >=20 > vw_bug =3D Car.new >=20 > then can you make the vw_bug go "vroooooom" and so forth? What would be= =20 > the usual way to do this in ruby? When a car is instantiated, should an= =20 > engine object get passed to the initializer method? >=20 > thanks, >=20 > Thufir vw_bug.engine.vroom() should return "vroooooom" if that's what you mean. Sorry, I'm having trouble understanding the question. Regards, =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart1801214.Iqxj1KZVsr Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHPna9CHB0oCiR2cwRAnPNAKDK671CjF2QrO7Q6lVD8nbHTxN+XACg13m0 mt1PQjNQEVAIscFUXKVL94Y= =yv3+ -----END PGP SIGNATURE----- --nextPart1801214.Iqxj1KZVsr--