Hi --

On Mon, 25 Nov 2002, 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,[])
> [[], []]
> >>> 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... ;]

$ ri Array.new
------------------------------------------------------------- Array::new
     Array.new( anInteger=0, anObject=nil ) -> anArray
------------------------------------------------------------------------
     Returns a new array, optionally with a size and initial value (that
     is, anInteger references to the same anObject).
        Array.new                #=> []
        Array.new(2)             #=> [nil, nil]
        Array.new(5, "A")        #=> ["A", "A", "A", "A", "A"]
        Array.new(2, Hash.new)   #=> [{}, {}]


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav