From: "Padma J." Date: 2012-09-18T11:27:27+09:00 Subject: Re: how to sum element of array Edward QU wrote in post #1074559: > dear all > > a_array=[2,4,6,8,10] > I want to sum the elements of the array: > 2+4+6+8+10 > how to write the script? > > many thanks! > best regards > Edward Hi Edward, You could also use the inject method from the Enumerable module like this: array.inject(0) { |sum, i| sum+i } Cheers. -- Posted via http://www.ruby-forum.com/.