Tell Ruby Program to Wait some amount of time

后端 未结 6 1320
渐次进展
渐次进展 2020-12-07 07:24

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

6条回答
  •  一向
    一向 (楼主)
    2020-12-07 08:13

    Use sleep like so:

    sleep 2
    

    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.)

提交回复
热议问题