Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

IO#autoclose=

(::boolish bool) -> ::boolish
io.autoclose = bool → true or false

Sets auto-close flag.

Example
f = File.open(File::NULL)
IO.for_fd(f.fileno).close
f.gets # raises Errno::EBADF

f = File.open(File::NULL)
g = IO.for_fd(f.fileno)
g.autoclose = false
g.close
f.gets # won't cause Errno::EBADF
See also #autoclose? #advise #<< #beep also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0