From: Rasputin Date: 2003-06-12T22:46:45+09:00 Subject: does each work on a copy? This has me confused (It's getting to be a frequent experience). ----------------8<---------------- SPACE = 1 a = Array.new(5) b = Array.new(5, SPACE) a.each { |el| el = SPACE } puts "a = #{a.join("-")}" puts "b = #{b.join("-")}" ----------------8<---------------- I'd expect to have a first output line similar to the second,but I get: rasputin@shrike rasputin$ ruby /tmp/q a = ---- b = 1-1-1-1-1 rasputin@shrike rasputin$ Now, is this because each is returning a copy of the element? It's the most plausible explanation (because if I replace a.each with a.collect! it works as I expected) but if so I'm surprised it hasn't bitten me on the ass before. I know the Array is full of nils, but can't see why that would cause what I'n seeing. Please hit me wirh a clue bat. Thanks. -- Rasputin :: Jack of All Trades - Master of Nuns