On Mon, Nov 25, 2002 at 07:42:19AM +0900, gminick wrote:
> Hi,
> 
> >>> a=[[],[]]
> [[], []]
> >>> a[0].push(1)
> [1]
> >>> a
> [[1], []]
> 
> Works great, isn't it ? :)
> Now, let's do "the same" with Array.new method:
> 
> >>> a=Array.new(2,[])

You create an array holding 2 references to the _same_ (empty) array.
In fact you're doing
tmp = []
a = Array.new(2,tmp)  #  a = [tmp, tmp]

Having later a[0] == a[1] shouldn't surprise you.

> [[], []]
> >>> a[0].push(1)
> [1]
> >>> a
> [[1], [1]]
> >>>
> 
> It isn't strange for me (I know that kind of behaviour from python), 
> but, is it documented anywhere ? I'm just searching for a point of 
> reference... ;]

http://www.glue.umd.edu/~billtj/ruby.html#default

-- 
 _           _                             
| |__   __ _| |_ ___ _ __ ___   __ _ _ __  
| '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ 
| |_) | (_| | |_\__ \ | | | | | (_| | | | |
|_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_|
	Running Debian GNU/Linux Sid (unstable)
batsman dot geo at yahoo dot com

"Who is General Failure and why is he reading my hard disk?"
Microsoft spel chekar vor sail, worgs grate !!
	-- Felix von Leitner, leitner / inf.fu-berlin.de