How to chunk an array in Ruby

Use each_slice:

require 'enumerator' # only needed in ruby 1.8.6 and before
userids.each_slice(100) do |a|
  # do something with a
end

Leave a Comment