Sha256: 9b612aed9fdcd7de8862c75cbedaa1e350f314ca8a00543a4e309c7540af31e6
Contents?: true
Size: 473 Bytes
Versions: 9
Compression:
Stored size: 473 Bytes
Contents
module Enumerable # Split on matching pattern. Unlike #divide this does not include matching elements. # # ['a1','a2','b1','a3','b2','a4'].split(/^b/) # => [['a1','a2'],['a3'],['a4']] # # CREDIT: Trans def split(pattern) memo = [] sect = [] each do |obj| if pattern === obj memo << sect sect = [] else sect << obj end end memo << sect memo.pop while memo.last == [] memo end end
Version data entries
9 entries across 9 versions & 1 rubygems