# File activesupport/lib/active_support/core_ext/array/grouping.rb, line 20defin_groups_of(number, fill_with = nil)
ifnumber.to_i<=0raiseArgumentError,
"Group size must be a positive integer, was #{number.inspect}"endiffill_with==falsecollection = selfelse# size % number gives how many extra we have;# subtracting from number gives how many to add;# modulo number ensures we don't add group of just fill.padding = (number-size%number) %numbercollection = dup.concat(Array.new(padding, fill_with))
endifblock_given?collection.each_slice(number) { |slice|yield(slice) }
elsecollection.each_slice(number).to_aendend