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
io.c
View on GitHub ↗
static VALUE
rb_io_set_autoclose(VALUE io, VALUE autoclose)
{
rb_io_t *fptr;
GetOpenFile(io, fptr);
if (!RTEST(autoclose))
fptr->mode |= FMODE_PREP;
else
fptr->mode &= ~FMODE_PREP;
return autoclose;
}
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