title: Initializing hash with default value and incrementing by 1
body: <p>I need a hash whose keys should have default value 0. (basically I'm making a counter). Keys are not known so I cannot initialize them in beginning. Also with every occurrence of the key, the value should increase by 1. </p>
  
  <p>I have come up with this:</p>
  
  <pre><code>hash = {}
  hash[key] ? hash[key]+=1 : hash[key]=0
  </code></pre>
  
  <p>This looks OK and short, but I don't like repeating <code>hash[key]</code> so many times in one line of code. Is there a better way to write this?</p>