title: How to calculate running total of array elements?
body: <p>I'm working in Rails 3.1 as a relative noob, and have managed to extract user Transaction amounts from the db  into a date-ordered array using this code (where date and amount_cents are db attributes):</p>
  
  <p>@user_trans = User.transactions.order("date").map  {|t| t.amount_cents}</p>
  
  <p>=> [1000, -350, -250, 600, 750, -450]</p>
  
  <p>I easily get a total of the array with:</p>
  
  <p>@user_trans.sum  => 1300</p>
  
  <p>But what I just can't figure out is an elegant way to iterate over each element of the array and add the first element to the second, second to third, etc., resulting in running totals:</p>
  
  <p>[1000, 650, 400, 1000, 1750, 1300]</p>
  
  <p>It seems that .each or .inject would be the method used, but outside of a clunky multi-line hack, I haven't found the magic syntax to do this, but it seems there should be a streamlined approach. Order IS important. Maybe regress off the total, then reverse?</p>
  
  <p>I sit at your feet with hopeful expectation... :)</p>