Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method · added in Ruby 3.2
IO#path
() -> ::String?
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 string path associated with self, or nil if there is no associated path:
Example
path = 'doc/maintainers.md' fd = File.open(path).fileno # => 6 IO.new(fd, path: path).path # => "doc/maintainers.md" IO.new(fd).path # => nil
Ruby version changes
-
3.2
-
Introduce
IO.new(..., path:)and promoteFile#pathtoIO#path. [Feature #19036]
-