From: Thomas Luedeke Date: 2012-10-03T03:49:05+09:00 Subject: 2D array strategies I'm a relative Ruby Nuby, and am running into some difficulty determining how to handle 2D arrays. An extremely common task I am using Ruby for is to post-process the output files of large engineering codes, and extract scattered information into structured output for visualization codes. Frequently this amounts to pulling the same information from multiple cases, and producing x vs. y1, y2, ..., yn data. It is easy to do this for a single array case, but the capacity for Ruby to handle 2D array data is quite strange (and even awkward) to me. Coming from a Fortran 90 type of background, multiple-dimension array structures are very simple. So getting to my question, what is a typical approach for a Ruby user to solve a problem of this sort: > Set up a data structure to store at least one set of x versus y data. > Parse a file, looking to identify x versus y data for the first case out of an indeterminant overall number of cases. > If I find a subsequent case, add on an x versus y1 set of data to the original data structure > Repeat until EOF. Since Ruby only does 1D arrays, is there a trick for an array of arrays? Or is this hash territory? How do I do the 2D equivalent of using the .push array command to add on more data to the original array? Are there are any particular Ruby resources that I need to go read up on and go practice in IRB? Respectfully, TPL -- Posted via http://www.ruby-forum.com/.