Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Kernel#sleep

(?nil) -> bot
(::Time::_Timeout duration) -> ::Integer
sleep(secs = nil) → slept_secs

Suspends execution of the current thread for the number of seconds specified by numeric argument secs, or forever if secs is nil; returns the integer number of seconds suspended (rounded).

Example
Time.new  # => 2008-03-08 19:56:19 +0900
sleep 1.2 # => 1
Time.new  # => 2008-03-08 19:56:20 +0900
sleep 1.9 # => 2
Time.new  # => 2008-03-08 19:56:22 +0900

Ruby version changes

  1. 3.0
See also #set_trace_func #spawn #select #sprintf also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0