Skip to content

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

class method

File.absolute_path?

(::path file_name) -> bool
File.absolute_path?(path) → true or false

Returns whether the given path is an absolute path:

Example
File.absolute_path?('/home') # => true
File.absolute_path?('lib')   # => false

The result is OS-dependent for some paths:

Example
File.absolute_path?('C:/')   # => true   # On Windows.
File.absolute_path?('C:/')   # => false  # Elsewhere.
See also .absolute_path .atime .basename also in 4.0 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0