2012/9/13 7stud -- <lists / ruby-forum.com>:
> Or even better:
>
> class Array
>   def sum1
>     initial_val_for_total = 0
>     inject(initial_val_for_total) {|total, array_element| total +=
> array_element}
>   end
> end

Sorry, but that's bad practice in best case. #inject doesn't depend on
the total being assigned to by the block; it depends on the value
returned by the block. Your code works, but somebody may be tempted to
do something like adding "p array_element" at the end and suddenly it
breaks for no obvious reason, if somebody believed the assignment was
essential.

-- Matma Rex