Alle venerdÃ¬ 18 maggio 2007, Sergio R. ha scritto:
the 2 element should have the “check” string dropped into the next
how would i go about setting that (or any other) element only?
Look at the documentation for Array.new (ri Array.new). Array.new(n,
creates an array with n entries, all containing the same object, obj.
see this comparing the entries’ object_id, or using equal?:
=> true. Since all entries contain the same object, when you modify it,
change shows everywhere in the array.
To fill the array with different empty arrays, you need to use the
Array.new which takes a block:
In this form, the block is called for each index, with the index as
(you can omit it here because you don’t need it). The result of the
stored in the corresponding entry. The point is that each time the block
called, a new empty array is created and stored in the returned array.
time, a.equal?(a) gives false.
I hope this helps