From: "Erik Bågfors" Date: 2002-01-25T23:21:33+09:00 Subject: Re: Serious Array Bug in Ruby 1.6.6? On Fri, 2002-01-25 at 15:11, Bill Tj wrote: > Hi, > > a = Array.new (n, something) > > will create n copies of that something? If that something is a > numeric or a literal string, all n members refer to the same object. > But if that something is a container, at least, then Ruby should > create n different container objects. Personally I think it's _very_ clear. ------------------------------------------------------------- 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) #=> [{}, {}] it sais "anObject". It even gives "nil" as default. It's one object. Why should it create many objects?? I'm really not following you here. The way I see it. Array.new(2,Hash.new) is the same as h = Hash.new Array.new(2,h) and that's very clear. It would break my POLS if it was in anotherway. Also trying to eval this by hand trying to guess how the interpeter does it would be like this Array.new(2, Hash.new) -> Array.new(2, {}) # that is.. Hash.new is done before Array.new. I don't know if this is what happens but in my head that's it :) Now, I really think that what you want to do should be possible but it shouldn't be in that way. /Erik -- Erik B�gfors | erik@bagfors.nu Supporter of free software | GSM +46 733 279 273 fingerprint: 6666 A85B 95D3 D26B 296B 6C60 4F32 2C0B 693D 6E32