Quantcast
Channel: Software Habit
Viewing all articles
Browse latest Browse all 11

Ruby Tips #364 – Cool Console Counter

$
0
0

This tip comes by way of: @starvo.

By using a counter in your ruby console script you can gain insight into long running actions for your application.

@photos = Photo.all
count = @photos.count
@photos.each_with_index do |photo, idx|
  # ... do a bunch of processing
  puts "#{(100.0 * idx / count).round(2)}%"
end
 
# When the script is run we will get a percentage complete counter like:
#=> 0.1%
#=> 0.2%
#=> 0.3%
#=> 0.4%
#=> ...

:)


Viewing all articles
Browse latest Browse all 11

Trending Articles