/ Published in: Other

Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# orginal article : http://blog.jayfields.com/2007/09/ruby-arraychunk.html class Array # divides an array into a smaller chunks # [1,2,3,4].divide_by 2 # => [[1,2],[3,4]] def divide_by(number_of_chunks) chunks = (1..number_of_chunks).collect { [] } self.each_with_index do |item, index| chunks[index % number_of_chunks] << item end chunks end alias / divide_by end
Comments
