http://ruby-doc.org/core/classes/Array.src/M002161.html
irb(main):001:0> a = [1,2,3,4]
=> [1, 2, 3, 4]
irb(main):002:0> a[2,0] = 55
=> 55
irb(main):003:0> a
=> [1, 2, 55, 3, 4]
irb(main):004:0> a[2,0] = *[100,200,300]
=> [100, 200, 300]
irb(main):005:0> a
=> [1, 2, 100, 200, 300, 55, 3, 4]
and for multidimensional:
irb(main):006:0> a = [[1,2,3],[4,5,6]]
=> [[1, 2, 3], [4, 5, 6]]
irb(main):007:0> a[0][1,0] = 55
=> 55
irb(main):008:0> a
=> [[1, 55, 2, 3], [4, 5, 6]]
Take into account that in Ruby arrays are not really
"multidimensional". They are just arrays that contain other arrays.
It's not ensures that each array of a "dimension" has the same length,
for example. When you do a[0] in the above, you get an array, on which
you call the = method.
Jesus.
···
On Wed, Jul 28, 2010 at 12:56 PM, Dave Castellano <dcastellano1@wideopenwest.com> wrote:
Jesús Gabriel y Galán wrote:
On Wed, Jul 28, 2010 at 4:02 AM, Dave Castellano >> <dcastellano1@wideopenwest.com> wrote:
� ]
# Randomly insert correct answer.
�x = rand(4)
�answer_choices.insert??? �correct_ans_1
�answer_choices.insert??? �correct_anno_1
I want to insert correct_ans_1 into position [x,0] and correct_anno_1
into position [x,0].
You nearly had it in that sentence:
answer_choices[0] = correct_ans_1
answer_choices[1] = correct_ano_1
(I assume you wanted to insert the correct_anno_1 in position 1 of the
array).
Jesus.
I actually want to insert rather than replace. Is there a way to do
that??