[ruby-core:92795] [Ruby trunk Feature#15868] Implement `File.absolute_path?`

From: eregontp@...
Date: 2019-05-23 12:04:20 UTC
List: ruby-core #92795
Issue #15868 has been updated by Eregon (Benoit Daloze).


`Pathname("C:/foo/bar").absolute?` should return `true` on Windows.
I think it does already:
https://github.com/ruby/ruby/blob/fe3ff5afb07e171fd950623c69abfbabbb2762a3/=
test/pathname/test_pathname.rb#L278-L282

On non-Windows platforms it will return `false`, which is correct for non-W=
indows platforms.

About `File.absolute_path?`, it sounds good to me.

----------------------------------------
Feature #15868: Implement `File.absolute_path?`
https://bugs.ruby-lang.org/issues/15868#change-78169

* Author: deivid (David Rodr=EDguez)
* Status: Open
* Priority: Normal
* Assignee: =

* Target version: =

----------------------------------------
Currently there's no way to check whether a path is absolute or not in a wa=
y that works accross OSs. The pathname library has the #absolute? method, b=
ut that only checks whether the path starts with a slash, which is not appr=
opriate for Windows.

I thought of reimplementing it as something like File.absolute_path(self) =
=3D=3D self, but that would mean accessing the filesystem, which I don't th=
ink 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? t=
o 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 G=
ithub: https://github.com/ruby/ruby/pull/2198). =


---Files--------------------------------
0001-Add-File.absolute_path.patch (3.24 KB)


-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next