On 13.01.2010 22:55, Zach Bartels wrote: > Hi all, > > Apologies for the long post, but just want to introduce myself Mission accomplished, I'd say. :) Welcome to Ruby. > Arrays/Hashes: This is a secondary question I have regarding > efficiency and speed.. It is highly likely I would be using both of > these in a given scenario, to hold game data coming from a database or > generated/updated by real-time calculations. Are there any > guidelines for which is more appropriate for a given situation? For > some tasks I definitely like the idea of using Hashes to keep track of > certain data, but can see a use for Arrays in other situations where > using a Hash may mean redundant data or redudant references to data.. you pretty much understood the guidelines already: Use what fits your situation. If you need key => value pairs, use a Hash. If you need an Array of data, use the array. If you read the Ruby Style Guide thread a few threads down, you'll notice it's the same answer here that I gave there. Basically, use what feels natural to the situation you are in. > So in general, are there speed considerations to take into account for > using one over the other? Probably not any you have to worry about (i.e. measurable, but not noticable). In any case, you trade off convenient access with a little speed. Speed you'd lose if you implemented, say, Array#keys "by hand". Especially in Ruby 1.9.1, Hashes keep their ordering, so the look up of key => value pairs would be rather fast, I guess (Ruby Gurus will certainly correct me, since I'll be wrong :P). As general advice, I wouldn't worry too much about speed just now, while you are getting into the Ruby language. Once you know your way around, you'll be able to judge the trade offs involved in using option A over option B. :) -- Phillip Gawlowski