From: Hans Mackowiak Date: 2013-06-25T16:44:41+09:00 Subject: Re: Sum method through while loops or iteration "Jesús Gabriel y Galán" wrote in post #1113505: > 2.- More functional styles: > > 2.0.0p195 :029 > a.inject(0) {|total, x| total + x} > => 10 > 2.0.0p195 :030 > a.inject(:+) > => 10 > there is a difference: [].inject(0) {|total, x| total + x} => 0 [].inject(:+) => nil so i think this would be the best: [].inject(0,:+) => 0 -- Posted via http://www.ruby-forum.com/.