title: How to implement an enumerator in Ruby?
body: <p>For example:</p>
  
  <pre><code>a = [1,2,3,4,5]
  a.delete_if { |x| x &gt; 3 }
  </code></pre>
  
  <p>is equivalent to:</p>
  
  <pre><code>a = [1,2,3,4,5]
  a.delete_if.each.each.each.each { |x| x &gt; 3 }
  </code></pre>
  
  <p>I know <code>a.delete_if</code> returns an enumerator. But how does it know it should delete object when the <code>each</code> block returns true? How to implement <code>delete_if</code> by hand(and in Ruby)?</p>