From: Robert Klemme Date: 2011-11-29T01:09:40+09:00 Subject: Re: Is high-speed sorting impossible with Ruby? 2011/11/28 Matthias Wächter : > On 28.11.2011 15:17, Gaurav C. wrote: >> >> What's the difference between Array.new(1e6+1) {|n| ""} and >> Array.new(1e6+1, "")? > > The first one creates one array with 1e6+1 _different_ empty strings. The > second one results in an array that holds 1e6+1 references to the _same_ > empty string. Another way to visualize this: irb(main):001:0> Array.new(4, "").map(&:object_id) => [135176100, 135176100, 135176100, 135176100] irb(main):002:0> Array.new(4, "").map(&:object_id).uniq => [135107180] irb(main):003:0> Array.new(4){""}.map(&:object_id) => [134679150, 134679140, 134679110, 134679080] irb(main):004:0> Array.new(4){""}.map(&:object_id).uniq => [134358730, 134358720, 134358710, 134358670] Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/