From: 7stud -- Date: 2007-11-25T06:49:48+09:00 Subject: Re: RFC - Recursive Array Method call acting on element batches unknown wrote: > > With an array of 200 elements > Call a method to act on 10 elements at a time > Repeat until all elements are processed. > Return the processed array. > Pre ruby 1.9: require 'enumerator' def sum(arr) total = 0 arr.each {|elmt| total += elmt} #faster than the ponderously slow inject method total end results = [] arr = Array.new(15) {|i| i} p arr arr.each_slice(10) do |portion| results << sum(portion) end p results --output:-- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14] [45, 60] -- Posted via http://www.ruby-forum.com/.