title: What is the "right" way to iterate through an array in Ruby?
body: <p>PHP, for all its warts, is pretty good on this count. There's no difference between an array and a hash (maybe I'm naive, but this seems obviously right to me), and to iterate through either you just do</p>
  
  <pre><code>foreach (array/hash as $key =&gt; $value)
  </code></pre>
  
  <p>In Ruby there are a bunch of ways to do this sort of thing:</p>
  
  <pre><code>array.length.times do |i|
  end
  
  array.each
  
  array.each_index
  
  for i in array
  </code></pre>
  
  <p>Hashes make more sense, since I just always use</p>
  
  <pre><code>hash.each do |key, value|
  </code></pre>
  
  <p>Why can't I do this for arrays? If I want to remember just one method, I guess I can use <code>each_index</code> (since it makes both the index and value available), but it's annoying to have to do <code>array[index]</code> instead of just <code>value</code>.</p>
  
  <hr>
  
  <p>Oh right, I forgot about <code>array.each_with_index</code>. However, this one sucks because it goes <code>|value, key|</code> and <code>hash.each</code> goes <code>|key, value|</code>! Is this not insane?</p>