Module: Polyfill::V2_3::Enumerable

Defined in:
lib/polyfill/v2_3/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#chunk_whileObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/polyfill/v2_3/enumerable.rb', line 4

def chunk_while
  block = ::Proc.new

  ::Enumerator.new do |yielder|
    output = []
    each do |element, *rest|
      elements = rest.any? ? [element, *rest] : element

      if output.empty? || block.call(output.last, elements)
        output.push(elements)
      else
        yielder << output
        output = [elements]
      end
    end
    yielder << output unless output.empty?
  end
end

#grep_v(pattern) ⇒ Object



23
24
25
26
27
# File 'lib/polyfill/v2_3/enumerable.rb', line 23

def grep_v(pattern)
  output = to_a - grep(pattern)
  output.map!(&::Proc.new) if block_given?
  output
end

#slice_before(*args) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/polyfill/v2_3/enumerable.rb', line 29

def slice_before(*args)
  if !args.empty? && block_given?
    raise ArgumentError, 'wrong number of arguments (given 1, expected 0)'
  end

  super
end