Skip to content

Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →

class method

IO.try_convert

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 · 4.0 · 3.4 · 3.2 · 3.1 · 3.0