title: Interpret Ruby Code
body: <p>I want to know what the following code does in ruby, and if the same can be done in other languages?</p>
  
  <pre><code>def func(a)
      $i ||= -1
      eval %w(1 -1 3 6 1 1 -1 2 4 1)[$i+=1]   
  end
  </code></pre>
  
  <p>I know that <code>$i</code> refers to the global variable if I'm not mistaken. But I don't know what the rest does and how I can do this in other programming languages.</p>