From 84fc2a33e346e28845e99da978c8b4a1f89730df Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sun, 4 Jan 2026 19:27:22 +0000 Subject: [PATCH 1/2] [DOC] Doc for Pathname#<=> --- lib/pathname_builtin.rb | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/lib/pathname_builtin.rb b/lib/pathname_builtin.rb index 878603d..ba36d42 100644 --- a/lib/pathname_builtin.rb +++ b/lib/pathname_builtin.rb @@ -239,7 +239,30 @@ def ==(other) alias eql? == unless method_defined?(:<=>, false) - # Provides for comparing pathnames, case-sensitively. + # call-seq: + # self <=> other -> -1, 0, 1, or nil + # + # Compares +self.to_s+ and +other.to_s+, + # evaluating their string contents, not their string lengths; + # see String#<=>. + # + # Returns: + # + # - +-1+, if +self+ is smaller. + # - +0+, if the two are equal. + # - +1+, if +self+ is larger. + # - +nil+, if +other+ is not a pathname. + # + # Examples: + # + # Pathname('a') <=> Pathname('b') # => -1 + # Pathname('a') <=> Pathname('ab') # => -1 + # Pathname('a') <=> Pathname('a') # => 0 + # Pathname('b') <=> Pathname('a') # => 1 + # Pathname('ab') <=> Pathname('a') # => 1 + # Pathname('a') <=> Pathname('A') # => 1 + # Pathname('a') <=> :a # => nil + # def <=>(other) return nil unless Pathname === other @path.tr('/', "\0") <=> other.path.tr('/', "\0") From d9b9cf605153814540d7373d01c7b073dae71ac8 Mon Sep 17 00:00:00 2001 From: BurdetteLamar Date: Sun, 4 Jan 2026 19:37:13 +0000 Subject: [PATCH 2/2] [DOC] More on Pathname#<=> --- ext/pathname/pathname.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 10d055f..4b44f20 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -15,18 +15,30 @@ get_strpath(VALUE obj) } /* - * Provides a case-sensitive comparison operator for pathnames. + * call-seq: + * self <=> other -> -1, 0, 1, or nil * - * 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 + * Compares +self.to_s+ and +other.to_s+, + * evaluating their string contents, not their string lengths; + * see String#<=>. + * + * Returns: + * + * - +-1+, if +self+ is smaller. + * - +0+, if the two are equal. + * - +1+, if +self+ is larger. + * - +nil+, if +other+ is not a pathname. + * + * Examples: + * + * Pathname('a') <=> Pathname('b') # => -1 + * Pathname('a') <=> Pathname('ab') # => -1 + * Pathname('a') <=> Pathname('a') # => 0 + * Pathname('b') <=> Pathname('a') # => 1 + * Pathname('ab') <=> Pathname('a') # => 1 + * Pathname('a') <=> Pathname('A') # => 1 + * Pathname('a') <=> :a # => nil * - * 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. */ static VALUE path_cmp(VALUE self, VALUE other)