Module: Enumerable

Defined in:
lib/fnordmetric/ext.rb

Instance Method Summary collapse

Instance Method Details

#each_with_log(total = nil, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
# File 'lib/fnordmetric/ext.rb', line 3

def each_with_log(total = nil, &block)
  log_every = ((total ||= self.count) / 150)
  self.each_with_index do |item, index|
    if index % log_every == 0
      STDOUT.puts "#{index}/#{total} (#{((index/total.to_f)*100).to_i}%)" 
    end
    block.call(item, index)
  end
end