On Thu, Sep 13, 2012 at 5:55 AM, 7stud -- <[email protected]> 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/ -- You received this message because you are subscribed to the Google Groups ruby-talk-google group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at https://groups.google.com/d/forum/ruby-talk-google?hl=en
