Sha256: 8f510f7db87839b21ed89e52738bc7a110fcd6e9d342821410ca20e8b3565d8a

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

module Polyfill
  module V2_3
    module Enumerable
      def chunk_while
        block = ::Proc.new

        enum_count =
          begin
            size
          rescue NameError
            count
          end

        return [self] if enum_count == 1

        ::Enumerator.new do |yielder|
          output = []
          each_cons(2).with_index(1) do |(a, b), run|
            if run == enum_count - 1
              if block.call(a, b)
                output.push(a, b)
                yielder << output
              else
                output.push(a)
                yielder << output
                yielder << [b]
              end
            else
              output.push(a)
              unless block.call(a, b)
                yielder << output
                output = []
              end
            end
          end
        end
      end

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

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

        super
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
polyfill-0.7.0 lib/polyfill/v2_3/enumerable.rb