From: "Peter v. N." Date: 2005-10-12T08:31:53+09:00 Subject: Re: multi-dimensional Arrays I got that! Your explanation is clear & simple. I'm really astonished as how fast everyone responds here. Thank you all..and wait for more to come from my side ;-) David A. Black wrote: > Hi -- > > On Wed, 12 Oct 2005, Peter v. N. wrote: > >> Thank you for all the replies! This is really great. >> >> But I still wonder (or play dumb here): >> >> what's the difference between >> >> arr = Array.new(3) { Array.new(3) } >> >> and >> >> arr = Array.new(3, Array.new(3)) > > > In the first one, the block is executed once each time to fill up the > array. It's like: > > arr = [Array.new(3),Array.new(3),Array.new(3)] > > So it's an array of three different arrays. > > The second one sets all three initial values to the *same* array. > It's like: > > inner = Array.new(3) > arr = [inner,inner,inner] > > So you've got an array of three copies of the same object, which of > course has major implications when you modify that object, etc. > > > David >