collectiveidea / awesomeness

Collective Idea's Awesomeness. A collection of useful Rails bits and pieces.

This URL has Read+Write access

awesomeness / lib / awesomeness / core_ext / enumerable.rb
d34a31b5 » brandon 2008-06-19 move Aarray#/ to Enumerable#/ 1 module Enumerable
2
3 # Divide into groups
9d1a4eba » brandon 2008-06-19 refactoring Enum#/, making ... 4 def chunk(number_of_chunks, padding = false)
401e63e2 » bryckbost 2008-07-01 fixing a math bug 5 chunk_size = (size.to_f / number_of_chunks).ceil
6 chunk_size = 1 if chunk_size < 1
7 returning enum_for(:each_slice, chunk_size).to_a do |result|
9d1a4eba » brandon 2008-06-19 refactoring Enum#/, making ... 8 result << [] while result.length < number_of_chunks
9 result.last.pad!(result.first.length, padding) unless padding == false
d34a31b5 » brandon 2008-06-19 move Aarray#/ to Enumerable#/ 10 end
11 end
9d1a4eba » brandon 2008-06-19 refactoring Enum#/, making ... 12 alias / chunk
d34a31b5 » brandon 2008-06-19 move Aarray#/ to Enumerable#/ 13
14 end