title: Is there a way inside a loop to know if you're on the final iteration?
body: <p>While iterating through an array (or any other enumerable), is there any clean and simple way to know if you're on the final iteration?</p>
  
  <p>For example, in a Rails view you might have a collection of things to display, and you might want to put a horizontal rule between them, but not before each one, and not after each one.  Only between them. I'm sure there are many other possible uses, but this is the one I think would be most common: displaying something <em>between</em> the data of the collection items themselves.</p>
  
  <p>I'm pretty sure there's no way other than switching <code>each</code> to <code>each_with_index</code> or <code>each.with_index</code> and adding a variable outside the iteration for the total count of items, and then checking at the end of the block.  </p>
  
  <p>Since it seems <em>very</em> unlikely that there is a built-in method of doing this with <code>each</code>, is it possible to create a method that gives you this ability without added code outside the iteration?  The simplest form (which is not quite what I'm looking for but may be a step in the right direction) might be something like </p>
  
  <pre><code>people.each.with_count.with_index(1) do |person, count, index|
    # ...
    do_something_in_between if index &lt; count
  end
  </code></pre>
  
  <p>But I would actually prefer something more like</p>
  
  <pre><code>people.each do |person|
    # ...
  end.between do
    do_something_in_between
  end
  </code></pre>
  
  <p>Would it be possible to make that work?</p>