unknown wrote:
> Hi --
> 
> 
> Think of it as a rite of passage :-)  Sort of like realizing that:
> 
>    array.each {|a| puts a }
> 
> can be written as:
> 
>    puts array
> 
> or that ^ and $ operate per line rather than per string in regular
> expressions.
> 
> 
> David

I have no problem with Array.new(size, obj), in fact I think it is a 
syntactically nice form. What I have a problem with is that it behaves 
differently, depending what the object is.

> a = Array.new(3,0)
=> [0, 0, 0]
> a[1] = 1
=> 1
> a
=> [0, 1, 0]

> b = Array.new(3,[])
=> [[], [], []]
> b[1] << 1
=> [1]
> b
=> [[1], [1], [1]]

> c = [[],[],[]]
=> [[], [], []]
> c[1] << 1
=> [1]
> c
=> [[], [1], []]


Why can't b behave like a in this case ( Tim I know you tried to explain 
it to me, but I just can't wrap my mind around it where the current 
behavior of b is actually useful). If anybody can show me a real-world 
example I will be quiet forever (on this subject). Promised :)
In my opinion b should behave like c.

Regards,
Armin
-- 
Posted via http://www.ruby-forum.com/.