Maintenance Ruby 3.3 gets fixes, but no new features. Switch to Ruby 4.0 →
instance method · added in Ruby 3.2
IO#path
path → string or nil
io.c
View on GitHub ↗
VALUE
rb_io_path(VALUE io)
{
rb_io_t *fptr = RFILE(io)->fptr;
if (!fptr)
return Qnil;
return rb_obj_dup(fptr->pathv);
}
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"
Ruby version changes
-
3.2
-
Introduce
IO.new(..., path:)and promoteFile#pathtoIO#path. [Feature #19036]
-