title: ruby adding to hash with array value
body: <p>I tried the following ruby code, which I thought would return a hash of word lengths to the words with those lengths. Instead it is empty.</p>
  
  <pre><code>map = Hash.new(Array.new)    
  strings = ["abc","def","four","five"]
  strings.each do |word|
    map[word.length] &lt;&lt; word  
  end   
  </code></pre>
  
  <p>However, if I modify it to</p>
  
  <pre><code>map = Hash.new
  strings = ["abc","def","four","five"]
  strings.each do |word|
    map[word.length] ||= []
    map[word.length] &lt;&lt; word  
  end
  </code></pre>
  
  <p>It does work.</p>
  
  <p>Doesn't the first version just create a hash whose default values are an empty array? In this case, I don't understand why the 2 blocks give different values.</p>