On Thu, Sep 13, 2012 at 5:55 AM, 7stud -- <lists / ruby-forum.com> wrote:
> However, with better variable names, it might be clearer what's going on
> with inject:
>
>
> class Array
>   def sum1
>     inject(0) {|total, array_element| total += array_element}
>   end

The assignment is totally superfluous.

>   def sum2
>     total = 0
>
>     self.each do |array_element|
>       total += array_element
>     end
>
>     total
>   end

Here "self." is superfluous. ;-)

Kind regards

robert


-- 
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/