From: Jamie Hodkinson Date: 2005-04-25T21:51:10+09:00 Subject: Re: Array::new Brilliant, thank you. On 4/25/05, Dave Baldwin wrote: > > On 25 Apr 2005, at 13:36, Jamie Hodkinson wrote: > > > Just had something unexpected - is this the correct behaviour? > > > > foo = Array.new(3,Array.new) > > foo[0] << 4 > > foo[1] << 5 > > foo[0] << 6 > > p foo > > > > outputs... > > > > [[4, 5, 6], [4, 5, 6], [4, 5, 6]] > > > > I realise what's happening here, and might have expected it if the > > first line was > > foo = Array.new(3,[]) > > > > I'm left with doing this: > > foo = (1..3).collect { [] } > > > > which doesn't exactly raise my heartbeat. Any other options? > > > > foo = Array.new(3){Array.new} > > gives you what you want. > > Dave. > > > Cheers > > > > Jamie > > > >