Sha256: e5989c9dac5e4b9a58495b8c3acb16ad0ce1668f5c33709cf5f27dd85c395d96

Contents?: true

Size: 813 Bytes

Versions: 17

Compression:

Stored size: 813 Bytes

Contents

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

  module Enumerable
    def slice_after(pattern = Backports::Undefined, &block)
      raise ArgumentError, 'both pattern and block are given' if pattern != Backports::Undefined && block
      raise ArgumentError, 'wrong number of arguments (given 0, expected 1)' if pattern == Backports::Undefined && !block
      enum = self
      block ||= proc {|elem| pattern === elem}
      Enumerator.new do |y|
        acc = []
        enum.each do |*elem|
          elem = elem.first if elem.length == 1
          acc << elem
          if block.call(elem)
            y.yield acc
            acc = []
          end
        end
        y.yield acc unless acc.empty?
      end
    end
  end
end

Version data entries

17 entries across 17 versions & 1 rubygems

Version Path
backports-3.25.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.24.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.24.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.23.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.22.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.22.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.21.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.20.2 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.20.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.20.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.19.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.18.2 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.18.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.18.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.17.2 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.17.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.17.0 lib/backports/2.2.0/enumerable/slice_after.rb