We want to process 1000 elements of an array at a time. What are the options for doing this in Ruby?
Obviously, one approach is to do a simple loop and slice 1000 elemen
We wound up using each_slice:
each_slice
array = [1,2,3,4,5,6,7,8,9,10] array.each_slice(3) do |group| puts group end
In Rails you can use in_groups_of:
array = [1,2,3,4,5,6,7,8,9,10] array.in_groups_of(3, false).each do |group| puts group end # => [[1, 2, 3], [4, 5, 6], [7, 8, 9], [10]]