Class: Progress::Enhancer

Inherits:
SimpleDelegator
  • Object
show all
Includes:
Enumerable
Defined in:
lib/progress/with_progress.rb

Instance Method Summary collapse

Methods included from Enumerable

#each_with_index_and_progress, #each_with_progress, #with_progress

Instance Method Details

#each(*args, &block) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/progress/with_progress.rb', line 24

def each(*args, &block)
  __getobj__.each(*args) do |*yielded|
    Progress.step do
      block.call(*yielded)
    end
  end
end

#lengthObject



32
33
34
35
36
37
38
39
40
# File 'lib/progress/with_progress.rb', line 32

def length
  if __getobj__.respond_to?(:length) && !__getobj__.is_a?(String)
    __getobj__.length
  elsif __getobj__.respond_to?(:to_a)
    __getobj__.to_a.length
  else
    __getobj__.inject(0){ |length, obj| length + 1 }
  end
end