# Array of arrays

**URL:** <https://www.ruby-forum.com/t/array-of-arrays/109964>\
**Category:** Ruby\
**Created:** [July 20, 2007, 6:37pm UTC](https://www.ruby-forum.com/t/array-of-arrays/109964 "2007-07-20T18:37:53Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![divya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@divya](https://www.ruby-forum.com/u/divya)\
**Post date:** [July 20, 2007, 6:37pm UTC](https://www.ruby-forum.com/t/array-of-arrays/109964/1 "2007-07-20T18:37:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![divya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@divya](https://www.ruby-forum.com/u/divya)\
**Post date:** [July 20, 2007, 6:43pm UTC](https://www.ruby-forum.com/t/array-of-arrays/109964/2 "2007-07-20T18:43:45Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![divya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@divya](https://www.ruby-forum.com/u/divya)\
**Post date:** [July 20, 2007, 10:26pm UTC](https://www.ruby-forum.com/t/array-of-arrays/109964/3 "2007-07-20T22:26:19Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![divya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@divya](https://www.ruby-forum.com/u/divya)\
**Post date:** [July 25, 2007, 11:44pm UTC](https://www.ruby-forum.com/t/array-of-arrays/109964/4 "2007-07-25T23:44:17Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![divya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/13edae/32.png) [@divya](https://www.ruby-forum.com/u/divya)\
**Post date:** [July 26, 2007, 12:46am UTC](https://www.ruby-forum.com/t/array-of-arrays/109964/5 "2007-07-26T00:46:31Z")

</div>

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