On 2003-05-01 00:22:47 +0900, Orion Hunter wrote:
> Conclusion: I understand why I can't pass Array.new as the default value in 
> Array.new.

You can (in Ruby 1.8]), just use a block:

irb(main):009:0> a = Array.new(4) { Array.new }
	=> [[], [], [], []]
irb(main):010:0> a.size.times { |i| a[i] << i } ; a
	=> [[0], [1], [2], [3]]

> However, I do _not_ understand why the first iterative approach does
> not work.  I obviously know how to acquire the desired result, but
> that doesn't quench my curiousity as to why the other does not work.
> Can I bother someone for some enlightenment?

The i isn't an alias for an array element unlike Perls $_. It's just
another reference to this element, and you changed only this reference
to point somewhere else in your code.

You could use map instead pass the correctly initialized array to a:

irb(main):011:0> a = Array.new(4).map { Array.new }
	=> [[], [], [], []]
irb(main):012:0> a.size.times { |i| a[i] << i } ; a
	=> [[0], [1], [2], [3]]