Sha256: a08aea89b75d26bdb7a5ad3b48e086e834df99806049c4ea9bf01bf6b32eb8cc

Contents?: true

Size: 722 Bytes

Versions: 38

Compression:

Stored size: 722 Bytes

Contents

unless Enumerable.method_defined? :slice_when
  require 'backports/tools/arguments'
  require 'backports/1.9.1/enumerator/new'

  module Enumerable
    def slice_when(&block)
      raise ArgumentError, 'tried to create Proc object without a block' unless block
      enum = self
      Enumerator.new do |y|
        acc = []
        prev = Backports::Undefined
        enum.each do |*elem|
          elem = elem.first if elem.length == 1
          unless prev == Backports::Undefined
            if block.call(prev, elem)
              y.yield acc
              acc = []
            end
          end
          acc << elem
          prev = elem
        end
        y.yield acc unless acc.empty?
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 3 rubygems

Version Path
backports-3.25.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.24.1 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.24.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.23.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.22.1 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.22.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.21.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.20.2 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.20.1 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.20.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.19.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.18.2 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.18.1 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.18.0 lib/backports/2.2.0/enumerable/slice_when.rb
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/backports-3.12.0/lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.17.2 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.17.1 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.17.0 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.16.1 lib/backports/2.2.0/enumerable/slice_when.rb
backports-3.16.0 lib/backports/2.2.0/enumerable/slice_when.rb