title: Magic First and Last Indicator in a Loop in Ruby/Rails?
body: <p>Ruby/Rails does lots of cool stuff when it comes to sugar for basic things, and I think there's a very common scenario that I was wondering if anyone has done a helper or something similar for.</p>
  
  <pre><code>   a = Array.new(5, 1)
  
     a.each_with_index do |x, i|
       if i == 0
         print x+1
       elsif i == (a.length - 1)
         print x*10
       else
          print x
       end
     end
  </code></pre>
  
  <p>Pardon the ugliness, but this gets at what one might want... is there a ruby way to do something to the first and last of a loop?</p>
  
  <p><strong>[EDIT]</strong> I think ideally this would be an extension on Array with parameters (array instance, all elements function,  first elements function,  last elements function)... but I'm open to other thoughts.</p>