From: David Alan Black Date: 2002-01-25T02:16:56+09:00 Subject: Re: Serious Array Bug in Ruby 1.6.6? Hello -- On Fri, 25 Jan 2002, William Djaja Tjokroaminata wrote: [observation that Array.new(2, Hash.new) contains the same Hash twice] > At least, probably the book should not give that example. In the more > general terms, probably Ruby should change the behavior of Array.new (n, > Hash.new) as opposite to, say, Array.new (n, "A"). By having all the > members refer to the same hash object, Ruby has violated the Priciple > of Least Surprise. Yes, probably it is more consistent in the way Ruby > behaves currently. However, when a person creates an array of hashes, I > don't think there is anybody who wants all the hashes to refer to the same > thing, because it is useless. It's pretty easy and cheap (typing-wise) to do what you're aiming for: a = Array.new(2).map { Hash.new } # (or would map! be more logical and/or efficient there?) so I'd tend not to see it as too desireable that the consistent behavior of Array.new be changed. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav