title: auto increment variable in Ruby
body: <p>How can I auto-increment a variable so each time it is used, it is incremented by one, starting with 0?</p>
  
  <p>For example: </p>
  
  <pre><code>i = i+1 || 0 
  
  arr[i] = "foo"
  arr[i] = "bar"
  arr[i] = "foobar"
  
  arr #=&gt; ["foo","bar","foobar"]
  </code></pre>
  
  <p>I'm getting a <code>NoMethodError</code> <strong>undefined method '+' for nil:NilClass</strong></p>