Module: Specjour::Among
- Defined in:
- lib/specjour/core_ext/array.rb
Instance Method Summary collapse
Instance Method Details
#among(group_size) ⇒ Object
3 4 5 6 7 8 9 10 11 12 |
# File 'lib/specjour/core_ext/array.rb', line 3 def among(group_size) group_size = 1 if group_size.zero? groups = Array.new(group_size) { [] } offset = 0 each do |item| groups[offset] << item offset = (offset == group_size - 1) ? 0 : offset + 1 end groups end |