Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > array of arrays

Reply
Thread Tools

array of arrays

 
 
Divya Badrinath
Guest
Posts: n/a
 
      07-20-2007
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/.

 
Reply With Quote
 
 
 
 
dblack@wobblini.net
Guest
Posts: n/a
 
      07-20-2007
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)

 
Reply With Quote
 
 
 
 
Divya Badrinath
Guest
Posts: n/a
 
      07-20-2007
unknown wrote:
> 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


Thank you.

I will try it.


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

 
Reply With Quote
 
Divya Badrinath
Guest
Posts: n/a
 
      07-25-2007
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/.

 
Reply With Quote
 
Stephen Ball
Guest
Posts: n/a
 
      07-25-2007
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 <> 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/.
>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Merging two arrays -> array of arrays Allen Walker Ruby 6 05-21-2010 04:53 AM
problem making an array of arrays (of arrays) Cec Tre Ruby 3 03-19-2010 02:02 PM
Multidimensional arrays and arrays of arrays Philipp Java 21 01-20-2009 08:33 AM
Two-dimensional array to array of arrays Kenneth Brody C Programming 2 12-21-2006 06:42 PM
Arrays Of Arrays: Is it an Array or Scalar? Hal Vaughan Perl Misc 5 02-06-2004 02:10 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57