Sha256: 6b76a4e4ea504e995c1adf5aa7db5f7fb9ca69c68ecc8f1d73aa88c87147a4d1

Contents?: true

Size: 451 Bytes

Versions: 2

Compression:

Stored size: 451 Bytes

Contents

# frozen_string_literal: true

class ProgressBar
  module WithProgress
    def each_with_progress(*args, &block)
      bar = ProgressBar.new(count, *args)
      if block
        each{ |obj| yield(obj).tap{ bar.increment! } }
      else
        Enumerator.new{ |yielder|
          each do |obj|
            (yielder << obj).tap{ bar.increment! }
          end
        }
      end
    end

    alias_method :with_progress, :each_with_progress
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
progress_bar-1.3.3 lib/progress_bar/with_progress.rb
progress_bar-1.3.2 lib/progress_bar/with_progress.rb