Sha256: 88685114c05586c7e4bd10b3e71de96631ad3df4396014832c71c10ef8c1916d

Contents?: true

Size: 599 Bytes

Versions: 10

Compression:

Stored size: 599 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

10 entries across 10 versions & 1 rubygems

Version Path
facets-2.8.4 lib/core/facets/enumerable/divide.rb
facets-2.8.3 lib/core/facets/enumerable/divide.rb
facets-2.8.2 lib/core/facets/enumerable/divide.rb
facets-2.8.1 lib/core/facets/enumerable/divide.rb
facets-2.8.0 lib/core/facets/enumerable/divide.rb
facets-2.7.0 lib/core/facets/enumerable/divide.rb
facets-2.6.0 lib/core/facets/enumerable/divide.rb
facets-2.5.0 lib/core/facets/enumerable/divide.rb
facets-2.5.1 lib/core/facets/enumerable/divide.rb
facets-2.5.2 lib/core/facets/enumerable/divide.rb