Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →
instance method
Pathname#root?
() -> bool
root? → true or false
pathname.c
View on GitHub ↗
static VALUE
path_root_p(VALUE self)
{
VALUE path = get_strpath(self);
if (RSTRING_LEN(path) == 0) return Qfalse;
const char *ptr = RSTRING_PTR(path), *end = RSTRING_END(path);
rb_encoding *enc = rb_enc_get(path);
const char *base = rb_enc_path_skip_prefix_root(ptr, end, enc);
return RBOOL(base == end);
}
Returns whether the path in self points to a root directory.
On a non-Windows system, a root directory path is one whose name begins with one or more slash characters (‘’/‘):
Example
Pathname('/').root? # => true Pathname('////').root? # => true Pathname('/usr').root? # => false Pathname('foo').root? # => false
Does not resolve dot directories:
Example
Pathname('/usr/.').root? # => false Pathname('/usr/..').root? # => false
On a Windows system, a root directory path is one whose name begins as above, or with a device letter followed by a colon character (':') and one or more slash characters (‘’/‘):
Example
Pathname('/').root? # => true Pathname('////').root? # => true Pathname('C:/').root? # => true Pathname('C:////').root? # => true Pathname('c:/').root? # => true Pathname('H:/').root? # => true Pathname('C:/m').root? # => false Pathname('C:').root? # => false