Sha256: e6a20dc08844450054a411d5f4839c47b7805fd30b24dffdb0735627e3dc7b2b
Contents?: true
Size: 897 Bytes
Versions: 1
Compression:
Stored size: 897 Bytes
Contents
module Polyfill module V2_2 module Enumerable def slice_after(pattern = nil) raise ArgumentError, 'both pattern and block are given' if pattern && block_given? raise ArgumentError, 'wrong number of arguments (given 0, expected 1)' if !pattern && !block_given? matcher = pattern || ::Proc.new enum_count = begin size rescue NameError count end ::Enumerator.new do |yielder| output = [] run = 1 each do |element, *rest| elements = rest.any? ? [element, *rest] : element output.push(elements) if matcher === elements || run == enum_count # rubocop:disable Style/CaseEquality yielder << output output = [] end run += 1 end end end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
polyfill-0.7.0 | lib/polyfill/v2_2/enumerable.rb |