lib/rbbt/util/misc/development.rb in rbbt-util-5.34.13 vs lib/rbbt/util/misc/development.rb in rbbt-util-5.34.14
- old
+ new
@@ -191,9 +191,19 @@
def self.try3times(&block)
insist(3, &block)
end
+ def self.chunk(array, num)
+ total = array.length
+ current = 0
+ while current < total
+ last = current + num - 1
+ yield array[current..last]
+ current = last + 1
+ end
+ end
+
# Divides the array into +num+ chunks of the same size by placing one
# element in each chunk iteratively.
def self.divide(array, num)
num = 1 if num == 0
chunks = []