ruby / pathname

Pathname represents the name of a file or directory on the filesystem, but not the file itself.
BSD 2-Clause "Simplified" License
26 stars 16 forks source link

Make Pathname comparable #40

Closed gmcgibbon closed 4 weeks ago

gmcgibbon commented 1 month ago

Fixes 20676

I tried comparing pathnames to see if one was a subdirectory of another, and noticed it implements <=> but doesn't include Comparable. This allows pathnames respond to comparison operators and methods like their backing strings do.

gmcgibbon commented 4 weeks ago

Looks like <=> doesn't behave the way I thought it did.

Pathname.include Comparable
Pathname("/a/b") <= Pathname("/a/b/c") # is true, but
Pathname("/a/b") <= Pathname("/a/c") # is also true

Closing. Thanks for the feedback on the issue! ❤️

Hanmac commented 3 weeks ago

I think Pathname should still implement Comparable when defining the <=> method