From: David Alan Black Date: 2002-01-26T18:48:39+09:00 Subject: Re: Serious Array Bug in Ruby 1.6.6? Hello -- On Sat, 26 Jan 2002, William Djaja Tjokroaminata wrote: > David Alan Black wrote: > > What counts as a container, though? > > ....... > > a = Array.new(2, Thing.new) # Container? > > > We know that Ruby has only two built-in containers and it has only defined > the shallow copy. The behavior of copying the containers (through > dup or clone) has been defined. When the nesting is more than one level, > then it is not Ruby responsibility anymore. Let me put it a somewhat different way: to the extent that you might want to fill your array with different instances of something, rather than with the same object, distinguishing between containers and non-containers isn't necessarily relevant. In other words, you might want all of the same container (no, I don't have a convincing example of this, but it's not impossible :-) or you might want different instances of class Something, even though Somethings are *not* containers. I think the container/non-container distinction has arisen because of the involvement of Hash in the example we've been discussing, but that distinction doesn't necessary coincide with what one might want or not want out of array initialization. So any kind of magic detection and decision-making by Ruby about what you want will always run the risk of getting it wrong. Meanwhile there's nothing you *can't* do (if not with the syntax of Array#new, then with #map or other methods) without that detection. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav