Skip to content

End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

IO#autoclose=

io.autoclose = bool → true or false

Sets auto-close flag.

Example
f = open("/dev/null")
IO.for_fd(f.fileno)
# ...
f.gets # may cause Errno::EBADF

f = open("/dev/null")
IO.for_fd(f.fileno).autoclose = false
# ...
f.gets # won't cause Errno::EBADF
See also #autoclose? #advise #<< #beep also in 4.1 · 4.0 · 3.4 · 3.3 · 3.2 · 3.1