Module: Vim::Flavor::EnumerableExtension

Defined in:
lib/vim-flavor/enumerableextension.rb

Instance Method Summary collapse

Instance Method Details

#after_each(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
# File 'lib/vim-flavor/enumerableextension.rb', line 17

def after_each(&block)
  vs = each
  Enumerator.new do |y|
    loop do
      v = vs.next
      y << v
      block.call(v)
    end
  end
end

#before_each(&block) ⇒ Object



6
7
8
9
10
11
12
13
14
15
# File 'lib/vim-flavor/enumerableextension.rb', line 6

def before_each(&block)
  vs = each
  Enumerator.new do |y|
    loop do
      v = vs.next
      block.call(v)
      y << v
    end
  end
end

#on_failure(&block) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vim-flavor/enumerableextension.rb', line 28

def on_failure(&block)
  vs = each
  Enumerator.new do |y|
    v = nil
    begin
      loop do
        v = vs.next
        y << v
        v = nil
      end
    rescue StopIteration
      raise
    rescue
      block.call(v)
      raise
    end
  end
end