Class: Array
- Inherits:
-
Object
- Object
- Array
- Defined in:
- lib/broadway/core_ext.rb
Instance Method Summary collapse
Instance Method Details
#/(len) ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/broadway/core_ext.rb', line 32 def / len a = [] each_with_index do |x,i| a << [] if i % len == 0 a.last << x end a end |
#chunk(pieces) ⇒ Object
27 28 29 30 |
# File 'lib/broadway/core_ext.rb', line 27 def chunk(pieces) q, r = length.divmod(pieces) (0..pieces).map { |i| i * q + [r, i].min }.enum_cons(2).map { |a, b| slice(a...b) } end |