Skip to content

End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →

instance method

IO#to_path

to_path

Alias of #path

Returns the path associated with the IO, or nil if there is no path associated with the IO. It is not guaranteed that the path exists on the filesystem.

Example
$stdin.path # => "<STDIN>"

File.open("testfile") {|f| f.path} # => "testfile"
See also #path #to_io #tty? #to_i also in 4.1 · 4.0 · 3.4 · 3.3