title: How can I use Array#delete while iterating over the array?
body: <p>I have an array that I want to iterate over and delete some of the elements. This doesn't work:</p>
  
  <pre><code>a = [1, 2, 3, 4, 5]
  a.each do |x|
    next if x &lt; 3
    a.delete x
    # do something with x
  end
  a #=&gt; [1, 2, 4]
  </code></pre>
  
  <p>I want <code>a</code> to be <code>[1, 2]</code>. How can I get around this?</p>