Ruby 2.4.0 リファレンスマニュアル > ライブラリ一覧 > 組み込みライブラリ > Kernelモジュール > sleep
sleep -> Integer
[permalink][rdoc]sleep(sec) -> Integer
sec 秒だけプログラムの実行を停止します。
sec が省略された場合、他スレッドからの Thread#run などで明示的に起こさない限り永久にスリープします。Thread#runを呼ぶとその時点で sleepの実行が中断されます。
it = Thread.new do
sleep
puts 'it_end'
end
re = sleep 2.11
puts re
it.run
re2 = sleep 0.76
puts re2
#=> 2
# it_end
# 1