End of Life Ruby 3.0 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
IO.try_convert
IO.try_convert(obj) → 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);
}
Try to convert obj into an IO, using to_io method. Returns converted IO or nil if obj cannot be converted for any reason.
Example
IO.try_convert(STDOUT) #=> STDOUT IO.try_convert("STDOUT") #=> nil require 'zlib' f = open("/tmp/zz.gz") #=> #<File:/tmp/zz.gz> z = Zlib::GzipReader.open(f) #=> #<Zlib::GzipReader:0x81d8744> IO.try_convert(z) #=> #<File:/tmp/zz.gz>