title: Ruby += assignment operator
body: <pre><code>foo = [10,20,30,40,50,60]
  foo_total = 0
  foo.each do |f|
   print foo_total += f
  end
  print foo_total
  </code></pre>
  
  <p>The output of this code sample will be <code>10 30 60 100 150 210 210</code> but I'm actually looking for <code>10 20 30 40 50 60 210</code>
  I know that it can be achieved by using the following code</p>
  
  <pre><code>foo = [10,20,30,40,50,60]
  foo_total = 0
  foo.each do |f|
   print f
   foo_total += f
  end
  print foo_total
  </code></pre>
  
  <p>However, is there a more elegant approach that needs just one line in the <code>foo.each</code> block?</p>
  
  <p>edit: It's not only about the output, but also about having the variable foo_total that contains the sum of all values in foo</p>