Sha256: 1a7b0ecf42bf5b26ac441ec3fcd1a04dc2c08d22d3b81b67cd8a7cc92b2472e0
Contents?: true
Size: 600 Bytes
Versions: 7
Compression:
Stored size: 600 Bytes
Contents
module Enumerable # Divide on matching pattern. # # ['a1','b1','a2','b2'].divide(/^a/) # => [['a1,'b1'],['a2','b2']] # # CREDIT: Trans def divide(pattern) memo = [] each do |obj| memo.push [] if pattern === obj memo.last << obj end memo end # DEPRECATED -- Use 'each_slice(n).to_a' as of 1.9. # Partition an array into parts of given length. # # CREDIT WhyTheLuckyStiff # # def / len # inject([]) do |ary, x| # ary << [] if [*ary.last].nitems % len == 0 # ary.last << x # ary # end # end end
Version data entries
7 entries across 7 versions & 2 rubygems