Sha256: 9f804d5e7f33ff9eff8a7dafa76648b995ba2ae526f968cbd5dc27f4bb97d9ba

Contents?: true

Size: 394 Bytes

Versions: 5

Compression:

Stored size: 394 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 = []
    each do |obj|
      if pattern === obj
        memo.push []
      else
        memo.last << obj
      end
    end
    memo
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
facets-2.4.0 lib/facets/enumerable/split.rb
facets-2.4.1 lib/facets/enumerable/split.rb
facets-2.4.2 lib/core/facets/enumerable/split.rb
facets-2.4.3 lib/core/facets/enumerable/split.rb
facets-2.4.4 lib/core/facets/enumerable/split.rb