How do you tell a Ruby program to wait an arbitrary amount of time before moving on to the next line of code?
相关问题
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
- Why Isn't My Windows 10 PC Waking Up after a S
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
sleep 6
will sleep for 6 seconds. For a longer duration, you can also usesleep(6.minutes)
orsleep(6.hours)
.Like this:
The
num_secs
value can be an integer or float.Also, if you're writing this within a Rails app, or have included the ActiveSupport library in your project, you can construct longer intervals using the following convenience syntax:
Use sleep like so:
That'll sleep for 2 seconds.
Be careful to give an argument. If you just run
sleep
, the process will sleep forever. (This is useful when you want a thread to sleep until it's woken.)