Sha256: ee618df13dd3c42e6f186549a473bf7e99fc8255016435c4c96c7052c8f41c46

Contents?: true

Size: 468 Bytes

Versions: 7

Compression:

Stored size: 468 Bytes

Contents

class Array

  # 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

7 entries across 6 versions & 1 rubygems

Version Path
facets-2.9.3 lib/core/facets/array/split.rb
facets-2.9.2 lib/core/facets/array/split.rb
facets-2.9.2 src/core/facets/array/split.rb
facets-2.9.1 lib/core/facets/array/split.rb
facets-2.9.0 lib/core/facets/array/split.rb
facets-2.9.0.pre.2 lib/core/facets/array/split.rb
facets-2.9.0.pre.1 lib/core/facets/array/split.rb