Sha256: fa8cff2fc77ad6230067a74f25549f1bf8595d8c77be04b1156dfa39b2e48360

Contents?: true

Size: 881 Bytes

Versions: 21

Compression:

Stored size: 881 Bytes

Contents

module Vim
  module Flavor
    EnumerableExtension = ::Enumerable

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

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

      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
    end
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
vim-flavor-1.0.0 lib/vim-flavor/enumerableextension.rb