开发者

How can I make this show only if the percentage changed? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form开发者_运维知识库. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜