Module: Enumerable

Defined in:
lib/core_ext/enumerable.rb

Overview

We enhance all enumerable objects (e.g. Array, Hash, Range, ...) by extending the Enumerable module. This mixin is only supposed to be present on objects that provide an #each method.

Instance Method Summary collapse

Instance Method Details

#with_progress(options = {}) ⇒ Enumerable Also known as: tqdm

Returns a clone of self where all calls to #each and related methods will print an animated progress bar while iterating.

Parameters:

  • options (Hash) (defaults to: {})

    more options used to control behavior of the progress bar

Options Hash (options):

  • :desc (String)

    a short description added to the beginning of the progress bar

  • :total (Integer) — default: self.size

    the expected number of iterations

  • :file (File, IO) — default: $stderr

    a file-like object to output the progress bar to

  • :leave (Boolean) — default: false

    should the progress bar should stay on screen after it's done?

  • :min_iters (Integer)

    see :min_interval

  • :min_interval (Float)

    If less than min_interval seconds or min_iters iterations have passed since the last progress meter update, it is not updated again.

Returns:

  • (Enumerable)

    self with the #each method wrapped as described above



21
22
23
# File 'lib/core_ext/enumerable.rb', line 21

def with_progress(options = {})
  Tqdm::Decorator.new(self, options).enhance
end