Array of arrays

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?

···

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

Hi --

···

On Sat, 21 Jul 2007, Divya Badrinath 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

--
* Books:
   RAILS ROUTING (new! http://www.awprofessional.com/title/0321509242\)
   RUBY FOR RAILS (http://www.manning.com/black\)
* Ruby/Rails training
     & consulting: Ruby Power and Light, LLC (http://www.rubypal.com)

unknown wrote:

Hi --

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.

···

On Sat, 21 Jul 2007, Divya Badrinath wrote:

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

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)
?

···

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

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"]]

···

On 7/25/07, Divya Badrinath <dbadrinath@dash.net> wrote:

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)
?
--
Posted via http://www.ruby-forum.com/\.