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

  def sum2
    total = 0

    self.each do |array_element|
      total += array_element
    end

    total
  end
end

puts [1, 2, 3].sum1
puts [1, 2, 3].sum2

--output:--
6
6

-- 
Posted via http://www.ruby-forum.com/.