如何在红宝石中每秒调用一个方法 [英] how to invoke a method for every second in ruby
本文介绍了如何在红宝石中每秒调用一个方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在红宝石中创建一个秒表程序,所以我用它搜索了一下,发现了这个 SO Q .
I wanted to create a stopwatch program in ruby so I googled it and found this SO Q.
但是在那儿,作者用1000xxx.times
调用了tick
函数.我想知道如何使用(every second).times
之类的方法或每增加一秒调用tick
函数.
But over there, the author calls the tick
function with 1000xxx.times
. I wanted to know how I can do it using something like (every second).times
or for each increment of second do call the tick
function.
推荐答案
Thread.new do
while true do
puts Time.now # or call tick function
sleep 1
end
end
这篇关于如何在红宝石中每秒调用一个方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文