On Sat, Jul 17, 2010 at 8:14 AM, Dave Howell
<groups.2009a / grandfenwick.net> wrote:
> OK, let's try this from the top. {grin} Here's some fresh new code:

Looks good :)

> Note that @data is no longer defined as "Array.new(@width) { Array.new(@h=
eight) }". I think I copied that from your code? but discovered that it gav=
e each row the SAME array, so that changing [1][3] caused every cell in tha=
t column to have the same value. Useless! Not the first time that feature o=
f Ruby (and it is a feature, wacky though it sometimes seems) has surprised=
 me.

That shouldn't have happened - the block passed to Array.new should
create a new array every time it's called.

irb(main):001:0> a =3D Array.new(5) { Array.new(3) }
=3D> [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil], [nil, nil,
nil], [nil, nil, nil]]

irb(main):002:0> a[1][2] =3D 0
=3D> 0

irb(main):003:0> a
=3D> [[nil, nil, nil], [nil, nil, 0], [nil, nil, nil], [nil, nil, nil],
[nil, nil, nil]]

irb(main):004:0> b =3D Array.new(5, Array.new(3))
=3D> [[nil, nil, nil], [nil, nil, nil], [nil, nil, nil], [nil, nil,
nil], [nil, nil, nil]]

irb(main):005:0> b[1][2] =3D 0
=3D> 0

irb(main):006:0> b
=3D> [[nil, nil, 0], [nil, nil, 0], [nil, nil, 0], [nil, nil, 0], [nil, nil=
, 0]]

martin