Numbering array values [multidimentional?!]

Hi,
I'm very new to Ruby (2 days), I'm mostly used to Python/PHP/C++.

What would be ideal would be a multidimensional array however from what
I have read Ruby does not support multidimensional arrays.

I want to be able to store data within multiple arrays and have the
values in all of the arrays linked together.

Example;

Array1
[vegetable]
[fruit]

Array2
[carrot]
[banana]

Array3
[tomato]
[apple]

I want to be able to some how output;

Vegetables;
carrot, tomato

Fruit;
banana, apple

With a multidimensional array this would be trivial;

[vegetable][carrot]
[vegetable][tomato]
[fruit][banana]
[fruit][apple]

Any help much appreciated,
Thank you.

···

--
Posted via http://www.ruby-forum.com/.

In general, multidimensional arrays are just arrays that contain arrays:

[[1,1,1],
[2,2,2],
[3,3,3]]

However, a Hash seems more appropriate for your specific use case:

{"vegetable" => ["carrot", "tomato"],
"fruit => ["banana", "apple"]}

···

On 2010-06-10 14:02:40 -0700, Safas Khkjh said:

Hi,
I'm very new to Ruby (2 days), I'm mostly used to Python/PHP/C++.

What would be ideal would be a multidimensional array however from what
I have read Ruby does not support multidimensional arrays.

I want to be able to store data within multiple arrays and have the
values in all of the arrays linked together.

Example;

Array1
[vegetable]
[fruit]

Array2
[carrot]
[banana]

Array3
[tomato]
[apple]

I want to be able to some how output;

Vegetables;
carrot, tomato

Fruit;
banana, apple

With a multidimensional array this would be trivial;

[vegetable][carrot]
[vegetable][tomato]
[fruit][banana]
[fruit][apple]

Any help much appreciated,
Thank you.

--
Rein Henrichs

http://reinh.com

Awesome! Just the thing I was looking for.

Thank you very much!

···

--
Posted via http://www.ruby-forum.com/.