sergio_101 wrote:>
> i have a plain old array initialized like this:
>
> @columns = Array.new
>
> this array needs to be an array of arrays..
>
> how do i tell ruby that this is an array of arrays?
>
> what i want to do is something like this:
>
> @columns[i] << ''some value''
>
> where is is determined programattically..
>
> obviously, ruby won''t let me do this since @columns[i] is not an
> array, but an array element..
>
Actually ruby is just fine with that. You can put any object in an array,
including other arrays. No
need to "tell" ruby anything special. Here''s an example:
irb(main):001:0> a = []
=> []
irb(main):003:0> b = [1,2,3]
=> [1, 2, 3]
irb(main):004:0> c = [4,5,6]
=> [4, 5, 6]
irb(main):005:0> a << b
=> [[1, 2, 3]]
irb(main):006:0> a << c
=> [[1, 2, 3], [4, 5, 6]]
irb(main):007:0> a[0] << 7
=> [1, 2, 3, 7]
irb(main):008:0> a
=> [[1, 2, 3, 7], [4, 5, 6]]
As long as there is an object at the index you specify and that object responds
to ''<<'', this code
will succeed.
b
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---