End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
IO.try_convert
IO.try_convert(object) → new_io or nil
io.c
View on GitHub ↗
static VALUE
rb_io_s_try_convert(VALUE dummy, VALUE io)
{
return rb_io_check_io(io);
}
Attempts to convert object into an IO object via method to_io; returns the new IO object if successful, or nil otherwise:
Example
IO.try_convert(STDOUT) # => #<IO:<STDOUT>> IO.try_convert(ARGF) # => #<IO:<STDIN>> IO.try_convert('STDOUT') # => nil