title: defining my_each in terms of my_times
body: <p>I'm reading <em>The Well-Grounded Rubyist</em> and have come across an extra credit challenge to which there is no answer. </p>
  
  <pre><code>class Array
    def my_each
      c = 0
      until c == size
        yield(self[c])
        c += 1
      end
      self
    end
  end
  </code></pre>
  
  <p>An example is given of creating a <code>my_each</code> with <code>my_times</code></p>
  
  <pre><code>class Array
    def my_each
      size.my_times do |i|
        yield self[i]
      end
      self
    end
  end
  </code></pre>
  
  <p>With the point that many of Ruby's iterators are built on top of <code>each</code> and not the other way around.</p>
  
  <p>Given the above <code>my_each</code>, how could I use it in an implementation of <code>my_times</code>?</p>
  
  <p>To make it clear, an example of a <code>my_times</code> implementation was given before:</p>
  
  <pre><code>class Integer
    def my_times
      c = 0
      until c == self
        yield(c)
        c += 1
      end
      self
    end
  end
  
  5.my_times { |e| puts "The block just got handed #{e}." }
  </code></pre>
  
  <p>So it would seem that the question most certainly implies using <code>my_each</code> in an implementation of <code>my_times</code>.</p>