From: 7stud -- Date: 2012-09-14T13:02:37+09:00 Subject: Re: Breaking Down the Block Robert Klemme wrote in post #1075769: > On Thu, Sep 13, 2012 at 5:55 AM, 7stud -- 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. > Whoops. Yep, otherwise it wouldn't be such a strange method. >> def sum2 >> total = 0 >> >> self.each do |array_element| >> total += array_element >> end >> >> total >> end > > Here "self." is superfluous. ;-) > Yep. I write it anyway. In my opinion, it's 10 times clearer with an explicit receiver. -- Posted via http://www.ruby-forum.com/.