> -----Original Message----- > From: ara.t.howard / noaa.gov [mailto:ara.t.howard / noaa.gov] > Sent: 13 November 2006 15:38 > To: ruby-talk ML > Subject: Re: classes within classes > > > > > +----------------------------picture-+ > > | +----------------------track1----+ | > > | | | | > > | | x x | | > > | | x x | | > > | | | | > > | | | | > > | +--------------------------------+ | > > | | > > | +----------------------track2----+ | > > | | | | > > | | xx | | > > | +--------------------------------+ | > > +------------------------------------+ > > > > As a track can _only_ be defined within a picture, and a > feature can > > _only_ be defined within a track, I have set up the classes > as follows: > > class Picture > > class Track > > class Feature > > end > > end > > end > > > this also has the nice feature that children prevent any > required parents from having the gc evaporate them - so long > as we have a reference up the object will not disappear. in > fact, i'd probably setup the association as a two-way: > > > class Picture > Tracks = [] > > def new_track *a, &b > t = Track.new self, *a, &b > ensure > Tracks << t > end > > def each_track &b > Tracks.each &b > end > > class Track > def initialize picture, *a, &b > @picture = picture > end > > Features = [] > > def new_feature *a, &b > f = Feature.new self, *a, &b > ensure > Features << f > end > > def each_feature &b > Features.each &b > end > > class Feature > def initialize track, *a, &b > @track = track > end > end > end > end > > > etc. Thanks. You really made that easy for me...