Module: Enumerable

Included in:
Progress::Enhancer
Defined in:
lib/progress/enumerable.rb

Instance Method Summary collapse

Instance Method Details

#each_with_index_and_progress(title = nil, &block) ⇒ Object

note that Progress.step is called automatically

Example

[1, 2, 3].each_with_index_and_progress('Numbers') do |number, index|
  sleep(number)
end


32
33
34
# File 'lib/progress/enumerable.rb', line 32

def each_with_index_and_progress(title = nil, &block)
  with_progress(title).each_with_index(&block)
end

#each_with_progress(title = nil, &block) ⇒ Object

note that Progress.step is called automatically

Example

[1, 2, 3].each_with_progress('Numbers') do |number|
  sleep(number)
end


23
24
25
# File 'lib/progress/enumerable.rb', line 23

def each_with_progress(title = nil, &block)
  with_progress(title).each(&block)
end

#with_progress(title = nil) ⇒ Object

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


14
15
16
# File 'lib/progress/enumerable.rb', line 14

def with_progress(title = nil)
  Progress::WithProgress.new(self, title)
end