Project

General

Profile

Actions

Feature #15868

closed

Implement `File.absolute_path?`

Added by deivid (David Rodríguez) about 3 years ago. Updated over 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:92794]

Description

Currently there's no way to check whether a path is absolute or not in a way that works accross OSs. The pathname library has the #absolute? method, but that only checks whether the path starts with a slash, which is not appropriate for Windows.

I thought of reimplementing it as something like File.absolute_path(self) == self, but that would mean accessing the filesystem, which I don't think we want here.

I also thought of implementing the "windows letter checks" in the pathname's library, but then I saw that those are already implemented in file.c, so I thought it would be a good idea to expose those. So I propose to add File.absolute_path? for this.

If this is accepted, I can do a follow-up PR to change Pathname#absolute? to delegate to File.absolute_path?.

What do you think?

I attach a patch to add File.absolute_path? here (I also opened a PR on Github: https://github.com/ruby/ruby/pull/2198).


Files

0001-Add-File.absolute_path.patch (3.24 KB) 0001-Add-File.absolute_path.patch deivid (David Rodríguez), 05/23/2019 09:53 AM
0001-Add-File.absolute_path.patch (3.24 KB) 0001-Add-File.absolute_path.patch With fixed test deivid (David Rodríguez), 05/23/2019 02:07 PM
Actions

Also available in: Atom PDF