diff --git a/file.c b/file.c index 0fdccb7d149be4..89294ea009e7b3 100644 --- a/file.c +++ b/file.c @@ -605,17 +605,31 @@ statx_mtimespec(const rb_io_stat_data *st) /* * call-seq: - * stat <=> other_stat -> -1, 0, 1, nil + * self <=> other -> -1, 0, 1, or nil * - * Compares File::Stat objects by comparing their respective modification - * times. + * Compares +self+ and +other+, by comparing their modification times; + * that is, by comparing self.mtime and other.mtime. * - * +nil+ is returned if +other_stat+ is not a File::Stat object + * Returns: * - * f1 = File.new("f1", "w") - * sleep 1 - * f2 = File.new("f2", "w") - * f1.stat <=> f2.stat #=> -1 + * - +-1+, if self.mtime is earlier. + * - +0+, if the two values are equal. + * - +1+, if self.mtime is later. + * - +nil+, if +other+ is not a File::Stat object. + * + * Examples: + * + * stat0 = File.stat('README.md') + * stat1 = File.stat('NEWS.md') + * stat0.mtime # => 2025-12-20 15:33:05.6972341 -0600 + * stat1.mtime # => 2025-12-20 16:02:08.2672945 -0600 + * stat0 <=> stat1 # => -1 + * stat0 <=> stat0.dup # => 0 + * stat1 <=> stat0 # => 1 + * stat0 <=> :foo # => nil + * + * \Class \File::Stat includes module Comparable, + * each of whose methods uses File::Stat#<=> for comparison. */ static VALUE diff --git a/object.c b/object.c index 93c8a483cfe26c..aaa3326ebf6df5 100644 --- a/object.c +++ b/object.c @@ -1766,21 +1766,33 @@ rb_obj_not_match(VALUE obj1, VALUE obj2) /* * call-seq: - * obj <=> other -> 0 or nil + * self <=> other -> 0 or nil * - * Returns 0 if +obj+ and +other+ are the same object - * or obj == other, otherwise nil. + * Compares +self+ and +other+. + * + * Returns: + * + * - +0+, if +self+ and +other+ are the same object, + * or if self == other. + * - +nil+, otherwise. + * + * Examples: + * + * o = Object.new + * o <=> o # => 0 + * o <=> o.dup # => nil + * + * A class that includes module Comparable + * should override this method by defining an instance method that: * - * The #<=> is used by various methods to compare objects, for example - * Enumerable#sort, Enumerable#max etc. + * - Take one argument, +other+. + * - Returns: * - * Your implementation of #<=> should return one of the following values: -1, 0, - * 1 or nil. -1 means self is smaller than other. 0 means self is equal to other. - * 1 means self is bigger than other. Nil means the two values could not be - * compared. + * - +-1+, if +self+ is less than +other+. + * - +0+, if +self+ is equal to +other+. + * - +1+, if +self+ is greater than +other+. + * - +nil+, if the two values are incommensurate. * - * When you define #<=>, you can include Comparable to gain the - * methods #<=, #<, #==, #>=, #> and #between?. */ static VALUE rb_obj_cmp(VALUE obj1, VALUE obj2) diff --git a/proc.c b/proc.c index 8a7a6ba8630822..441d2523233fa8 100644 --- a/proc.c +++ b/proc.c @@ -4048,19 +4048,18 @@ rb_proc_compose_to_right(VALUE self, VALUE g) /* * call-seq: - * meth << g -> a_proc + * self << g -> a_proc * - * Returns a proc that is the composition of this method and the given g. - * The returned proc takes a variable number of arguments, calls g with them - * then calls this method with the result. + * Returns a proc that is the composition of the given +g+ and this method. * - * def f(x) - * x * x - * end + * The returned proc takes a variable number of arguments. It first calls +g+ + * with the arguments, then calls +self+ with the return value of +g+. + * + * def f(ary) = ary << 'in f' * * f = self.method(:f) - * g = proc {|x| x + x } - * p (f << g).call(2) #=> 16 + * g = proc { |ary| ary << 'in proc' } + * (f << g).call([]) # => ["in proc", "in f"] */ static VALUE rb_method_compose_to_left(VALUE self, VALUE g) @@ -4072,19 +4071,18 @@ rb_method_compose_to_left(VALUE self, VALUE g) /* * call-seq: - * meth >> g -> a_proc + * self >> g -> a_proc * - * Returns a proc that is the composition of this method and the given g. - * The returned proc takes a variable number of arguments, calls this method - * with them then calls g with the result. + * Returns a proc that is the composition of this method and the given +g+. * - * def f(x) - * x * x - * end + * The returned proc takes a variable number of arguments. It first calls +self+ + * with the arguments, then calls +g+ with the return value of +self+. + * + * def f(ary) = ary << 'in f' * * f = self.method(:f) - * g = proc {|x| x + x } - * p (f >> g).call(2) #=> 8 + * g = proc { |ary| ary << 'in proc' } + * (f >> g).call([]) # => ["in f", "in proc"] */ static VALUE rb_method_compose_to_right(VALUE self, VALUE g)