Benedikt Heinen <ruby / ml.icemark.net> writes:

> On Thu, 9 Nov 2006, Friedrich Dominicus wrote:
>
>> I can not remember having read about it before, however the following
>> happens here:
>>
>> irb(main):015:0> arr = Array.new(3, Array.new)
>
> [...]
>
>> irb(main):018:0> arr1 = Array.new(3)
>> [nil, nil, nil]
>> irb(main):019:0> 0.upto(2) {|i| arr1[i] = Array.new}
>> 0
>
> [...]
>
>> I'm not getting it. Is it supposed to work that way?
>
> Yes. In your first call, 'Array.new' is evaluated ONCE before the call, 
> and hence all array members get initialised to use the SAME array.
Yeah it has come to me this night that it's supposed to be right. 

Anyway thanks for taking the time to answer

Regards
Friedrich

-- 
Please remove just-for-news- to reply via e-mail.