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
file.c
View on GitHub ↗
static VALUE
s_absolute_path_p(VALUE klass, VALUE fname)
{
VALUE path = rb_get_path(fname);
if (!rb_is_absolute_path(RSTRING_PTR(path))) return Qfalse;
return Qtrue;
}
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.