
14 Aug
2024
14 Aug
'24
9 a.m.
Issue #20676 has been updated by byroot (Jean Boussier).
to check if pathnames are subdirectories of each other
I don't understand. ```ruby
Pathname("/a/b").to_s <= Pathname("/a/b/c").to_s => true Pathname("/a/b").to_s <= Pathname("/a/c").to_s => true
`<=` doesn't tell you the right hand-side is a subdirectory of the left hand-side.
----------------------------------------
Feature #20676: Pathnames aren't Comparable
https://bugs.ruby-lang.org/issues/20676#change-109414
* Author: gmcgibbon (Gannon McGibbon)
* Status: Open
----------------------------------------
👋
I was working with Pathnames recently and noticed that I could do:
```rb
Pathname("/a/b").to_s <= Pathname("/a/b/c").to_s
but could not do: ```rb Pathname("/a/b") <= Pathname("/a/b/c") ``` to check if pathnames are subdirectories of each other. Pathname implements [`<=>`](https://docs.ruby-lang.org/en/master/Pathname.html#method-i-3C-3D-3E) with case insensitive matching for use-cases like this, but does not include Comparable. I think Pathname should include Comparable. I've opened a [PR here](https://github.com/ruby/pathname/pull/40) for your consideration. Thanks! -- https://bugs.ruby-lang.org/