Sha256: f39a7c283388c6533f77520113206b1de61654fbc91370f9c079e2f58d765522

Contents?: true

Size: 816 Bytes

Versions: 21

Compression:

Stored size: 816 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.new{|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

21 entries across 21 versions & 3 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/backports-3.12.0/lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.16.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.16.0 lib/backports/2.2.0/enumerable/slice_after.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/backports-3.15.0/lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.15.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.14.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.13.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.12.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.11.4 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.11.3 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.11.2 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.11.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.11.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.10.3 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.10.2 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.10.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.10.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.9.1 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.9.0 lib/backports/2.2.0/enumerable/slice_after.rb
backports-3.8.0 lib/backports/2.2.0/enumerable/slice_after.rb