Karthik
below are two examples first is for 2 dimensional array and second for 3
dimension
irb(main):001:0> mar = [[1,2],[3,4],[5,6]] #this creates 2 dimensional array
called mar
=> [[1, 2], [3, 4], [5, 6]]
irb(main):002:0> mar[1][0] #to access value 3 we have to access 2nd element
of mar which is an array and then 1st element of that array
=> 3
irb(main):003:0> mar3 = [[[1,2],[3,4]], [[5,6],[7,8]], [[9,10],[11,12]]] #
this creates 3 dimensional array mar3
=> [[[1, 2], [3, 4]], [[5, 6], [7, 8]], [[9, 10], [11, 12]]]
irb(main):004:0> mar3[2][1][1] # value 12 is in 3rd element of mar3, in it
its the 2nd element is [11,12] and in it 2nd element is value 12
=> 12
irb(main):005:0>
I hope this helps
-daya
On 8/2/06, Narayana Karthik <narayana_karthik_2004@hotmail.com>
wrote:>
>
>
> how to implement multi dimensional array in ruby
> in ruby multi dimension array look like tree structure
> plz help me & explain with code
> have a pleasant day
> thx
> narayana
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060802/5679838d/attachment.html