Module: ProgressBar::WithProgress

Defined in:
lib/progress_bar/with_progress.rb

Instance Method Summary collapse

Instance Method Details

#each_with_progress(*args, &block) ⇒ Object Also known as: with_progress


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/progress_bar/with_progress.rb', line 5

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