An alternate implementation of the Pathname class
APACHE-2.0 License
A drop-in replacement for the current Pathname class.
gem install pathname2
gem cert --add <(curl -Ls https://raw.githubusercontent.com/djberg96/pathname2/main/certs/djberg96_pub.pem)
require 'pathname2'
# Unix
path1 = Pathname.new("/foo/bar/baz")
path2 = Pathname.new("../zap")
path1 + path2 # "/foo/bar/zap"
path1 / path2 # "/foo/bar/zap" (same as +)
path1.exists? # Does this path exist?
path1.dirname # "/foo/bar"
path1.to_a # ['foo','bar','baz']
# Windows
path1 = Pathname.new("C:/foo/bar/baz")
path2 = Pathname.new("../zap")
path1 + path2 # "C:\\foo\\bar\\zap"
path1.root # "C:\\"
path1.to_a # ['C:','foo','bar','baz']
All forward slashes are converted to backslashes for Pathname objects.
If your pathname consists solely of ".", or "..", the return value for Pathname#clean will be different. On Win32, "\" is returned, while on Unix "." is returned. I consider this an extreme edge case and will not worry myself with it.
to_a
and root
instance methods.Pathname#cleanpath
method works differently - it always returnsPathname#+
method auto cleans.Pathname#clean
works slightly differently. In the stdlib version,Pathname#clean("../a")
returns "../a". In this version, it returns "a".Pathname#relative_path_from
.pn
method as a shortcut.Because there is some overlap in method names between File, Dir, and FileUtils, the priority is as follows:
In other words, whichever of these defines a given method first is the method that is used by the pathname2 library.
On MS Windows, some methods may not work on pathnames greater than 260 characters because of internal function limitations.
Any issues you find should be reported on the project page at https://github.com/djberg96/pathname2
None at this time. Suggestions welcome.
Apache-2.0
(C) 2003-2021 Daniel J. Berger All rights reserved.
This library is provided "as is" and without any express or implied warranties, including, without limitation, the implied warranties of merchantability and fitness for a particular purpose.
Daniel J. Berger