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



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

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