user94154 user94154 - 1 year ago 79
Ruby Question

Tell Ruby Program to Wait some amount of time

How do you tell a Ruby program to wait an arbitrary amount of time before moving on to the next line of code?

Answer Source

It's pretty easy:


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 elsewhere in your project, you can construct longer intervals using the following convenience syntax:

# or, even longer...
sleep(2.hours); sleep(3.days) # etc., etc.
#Or shorter
sleep(0.5) #Half a second
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download