Skip to content

Maintenance Ruby 3.4 gets fixes, but no new features. Switch to Ruby 4.0 →

instance method

Pathname#<=>

(untyped other) -> 0?
<=>(p1)

Provides a case-sensitive comparison operator for pathnames.

Example
Pathname.new('/usr') <=> Pathname.new('/usr/bin')
    #=> -1
Pathname.new('/usr/bin') <=> Pathname.new('/usr/bin')
    #=> 0
Pathname.new('/usr/bin') <=> Pathname.new('/USR/BIN')
    #=> 1

It will return -1, 0 or 1 depending on the value of the left argument relative to the right argument. Or it will return nil if the arguments are not comparable.

See also #/ #== #+ #=== also in 4.1 · 4.0 · 3.3 · 3.2 · 3.1 · 3.0