On Nov 28, 2011, at 3:17 PM, Gaurav C. wrote: > Douglas Seifert wrote in post #1034017: >>> >>>> a = Array.new(1e6+1) {|n| ""} >>> >> >> The above creates an Array of 1,000,001 slots. The block syntax lets >> you >> provide a default object dynamically. The first time you reference a >> particular index in the array, the block is called to allocate the >> default >> object at that position. >> > > Hi Doug, > > Thanks for the explanation. > Didn't understand the Array initialization part. > What's the difference between Array.new(1e6+1) {|n| ""} and > Array.new(1e6+1, "")? The former always returns a new string instance (this is what you want); the former creates one string and always returns a reference.