How can I make this show only if the percentage changed? [closed]
I'm stuck here:
puts "#{percent_finished.round}% uploading complete" ? if/unless ...
If percent_finished
is part of an ActiveRecord model, you can actually just make a call to percent_finished_changed?
.
For example:
puts "#{percent_finished.round}% uploading complete" if percent_finished_changed?
Here's some documentation:
http://ar.rubyonrails.org/classes/ActiveRecord/Dirty.html
Is this a command line tool?
last_percent = nil
upload_loop do
# ...
percent_rounded = percent_finished.round
puts "#{percent_rounded}% uploading complete" if percent_rounded != last_percent
last_percent = percent_rounded
end
精彩评论