Skip to content
class method

IO.try_convert

(::_ToIO obj) -> ::IO
(untyped obj) -> ::IO?
IO.try_convert(object) → new_io or nil

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
See also .sysopen .write .select #<< also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0