Array of arrays


#1

i have a database with some 10 records each containing 2 columns,
sno,name,city.

I want to push this into an array of arrays.
i see that Ruy doesnt support multi-dimensional arrays.
Any ideas of how to do it?


#2

Hi –

On Sat, 21 Jul 2007, Divya B. wrote:

i have a database with some 10 records each containing 2 columns,
sno,name,city.

I want to push this into an array of arrays.
i see that Ruy doesnt support multi-dimensional arrays.
Any ideas of how to do it?

Just use arrays as array elements:

[ [1,2,3], [4,5,6], [7,8,9] ]

for example.

David


#3

unknown wrote:

Hi –

On Sat, 21 Jul 2007, Divya B. wrote:

i have a database with some 10 records each containing 2 columns,
sno,name,city.

I want to push this into an array of arrays.
i see that Ruy doesnt support multi-dimensional arrays.
Any ideas of how to do it?

Just use arrays as array elements:

[ [1,2,3], [4,5,6], [7,8,9] ]

for example.

David

Thank you.

I will try it.


#4

I didnt get it.
I am new to Ruby.

i want it to be like this.
row = { " “a”,“b”,“c” ",
" “d”,“e”,“f” ",
" “g”,“h”,“i” "}
sow that
row[0] gives “a”,“b”,“c”
and row[1] gives “d”,“e”,“f”

say if
col is an array and
col = “a”,“b”,“c”

can i do
row.push(col)
?


#5

Try this,

irb(main):001:0> row = [[“a”,“b”,“c”],[“d”,“e”,“f”],[“g”,“h”,“i”]]
=> [[“a”, “b”, “c”], [“d”, “e”, “f”], [“g”, “h”, “i”]]
irb(main):002:0> row[0]
=> [“a”, “b”, “c”]
irb(main):003:0> row[1]
=> [“d”, “e”, “f”]

For your push operation you can use <<, as in:

irb(main):004:0> addition = [“j”,“k”,“l”]
=> [“j”, “k”, “l”]
irb(main):005:0> row << addition
=> [[“a”, “b”, “c”], [“d”, “e”, “f”], [“g”, “h”, “i”], [“j”, “k”, “l”]]