Skip to content

Preview Ruby 4.1 is a preview. It can change before the final release. Switch to Ruby 4.0 →

instance method

Pathname#relative?

() -> bool
relative? → true or false

Returns whether self contains a relative path:

Example
Pathname('lib').relative?   # => true
Pathname('/home').relative? # => false

The result is OS-dependent for some paths:

Example
Pathname('C:/').relative?   # => false # On Windows.
Pathname('C:/').relative?   # => true  # Elsewhere.