From: Kevin Smith Date: 2001-01-02T16:33:01+09:00 Subject: [ruby-talk:8504] Re: Hash access method Dave Thomas wrote: >tonys@myspleenklug.on.ca (tony summerfelt) writes: > >> > But do you ever do things like iterate over them, or access them by name? >> >> i will have to iterate over them. each planet has a ship production value. so >> the number of ships is going increase every year. for every planet i'll >> need: >> >> a.ships =a.ships + a.production >> >> and i need that 26 times. you can see why i'm looking for a solution. > >Here I think I'd be looking at an array or some other collection: > > planets.each do |planet| > planet.ships += planet.production > end > >or something similar. I happen to be writing a similar game right now :- ) And yes, I have an Array of Ship objects, and an Array of Planet objects. Works great. Highly recommended. Kevin