title: Ruby hash default value behavior
body: <p>I'm going through Ruby Koans, and I hit #41 which I believe is this:</p>
  
  <pre><code>def test_default_value_is_the_same_object
    hash = Hash.new([])
  
    hash[:one] &lt;&lt; "uno"
    hash[:two] &lt;&lt; "dos"
  
    assert_equal ["uno","dos"], hash[:one]
    assert_equal ["uno","dos"], hash[:two]
    assert_equal ["uno","dos"], hash[:three]
  
    assert_equal true, hash[:one].object_id == hash[:two].object_id
  end
  </code></pre>
  
  <p>It could not understand the behavior so I Googled it and found <a href="https://stackoverflow.com/questions/2698460/strange-ruby-behavior-when-using-hash-new">Strange ruby behavior when using Hash default value, e.g. Hash.new([])</a> that answered the question nicely.</p>
  
  <p>So I understand how that works, my question is, why does a default value such as an integer that gets incremented not get changed during use?  For example:</p>
  
  <pre><code>puts "Text please: "
  text = gets.chomp
  
  words = text.split(" ")
  frequencies = Hash.new(0)
  words.each { |word| frequencies[word] += 1 }
  </code></pre>
  
  <p>This will take user input and count the number of times each word is used, it works because the default value of 0 is always used.</p>
  
  <p>I have a feeling it has to do with the <code>&lt;&lt;</code> operator but I'd love an explanation.</p>