Method: Array#split

Defined in:
lib/core/facets/array/split.rb

#split(pattern) ⇒ Object

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



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/core/facets/array/split.rb', line 10

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