Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 22 additions & 8 deletions file.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <tt>self.mtime</tt> and <tt>other.mtime</tt>.
*
* +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 <tt>self.mtime</tt> is earlier.
* - +0+, if the two values are equal.
* - +1+, if <tt>self.mtime</tt> 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
Expand Down
34 changes: 23 additions & 11 deletions object.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <code>obj == other</code>, otherwise nil.
* Compares +self+ and +other+.
*
* Returns:
*
* - +0+, if +self+ and +other+ are the same object,
* or if <tt>self == other</tt>.
* - +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)
Expand Down
34 changes: 16 additions & 18 deletions proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 <i>g</i>.
* The returned proc takes a variable number of arguments, calls <i>g</i> 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)
Expand All @@ -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 <i>g</i>.
* The returned proc takes a variable number of arguments, calls this method
* with them then calls <i>g</i> 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)
Expand Down