Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Dir#path
() -> ::String?
path → string or nil
dir.c
View on GitHub ↗
static VALUE
dir_path(VALUE dir)
{
struct dir_data *dirp;
TypedData_Get_Struct(dir, struct dir_data, &dir_data_type, dirp);
if (NIL_P(dirp->path)) return Qnil;
return rb_str_dup(dirp->path);
}
If self was created with a string path, returns that path:
Example
dirpath = 'doc/tmp' Dir.mkdir(dirpath) dir = Dir.new(dirpath) dir.path # => "../ruby/doc/syntax"
The path remains even when the directory is removed:
Example
Dir.rmdir(dirpath) dir.path # => "../ruby/doc/syntax"
If self was created with a file descriptor, returns nil:
Example
dir0 = Dir.new('.') fd = dir0.fileno # => 8 dir1 = Dir.for_fd(fd) dir1.path # => nil