Sha256: c5b2478cdbdefd47c51c288d09f0d322d8f13ae19353b98241e0573b2edcd91f

Contents?: true

Size: 1016 Bytes

Versions: 1

Compression:

Stored size: 1016 Bytes

Contents

require 'enumerator'
module Enumerable
  # executes any Enumerable method with progress
  # note that methods which don't necessarily go through all items (like find or any?) will not show 100%
  # ==== Example
  #   [1, 2, 3].with_progress('Numbers').each do |number|
  #     sleep(number)
  #   end
  #   [1, 2, 3].with_progress('Numbers').each_cons(2) do |numbers|
  #     p numbers
  #   end
  def with_progress(title = nil)
    Progress::WithProgress.new(self, title)
  end

  # note that Progress.step is called automatically
  # ==== Example
  #   [1, 2, 3].each_with_progress('Numbers') do |number|
  #     sleep(number)
  #   end
  def each_with_progress(title = nil, &block)
    with_progress(title).each(&block)
  end

  # note that Progress.step is called automatically
  # ==== Example
  #   [1, 2, 3].each_with_index_and_progress('Numbers') do |number, index|
  #     sleep(number)
  #   end
  def each_with_index_and_progress(title, &block)
    with_progress(title).each_with_index(&block)
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
progress-0.3.0 lib/progress/enumerable.rb