Skip to content

Commit 0cdbaa9

Browse files
[DOC] Enhanced RDoc for <=> (#65)
1 parent 4246441 commit 0cdbaa9

File tree

1 file changed

+34
-10
lines changed

1 file changed

+34
-10
lines changed

ext/date/date_core.c

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6708,19 +6708,43 @@ cmp_dd(VALUE self, VALUE other)
67086708

67096709
/*
67106710
* call-seq:
6711-
* d <=> other -> -1, 0, +1 or nil
6711+
* self <=> other -> -1, 0, 1 or nil
67126712
*
6713-
* Compares the two dates and returns -1, zero, 1 or nil. The other
6714-
* should be a date object or a numeric value as an astronomical
6715-
* Julian day number.
6713+
* Compares +self+ and +other+, returning:
67166714
*
6717-
* Date.new(2001,2,3) <=> Date.new(2001,2,4) #=> -1
6718-
* Date.new(2001,2,3) <=> Date.new(2001,2,3) #=> 0
6719-
* Date.new(2001,2,3) <=> Date.new(2001,2,2) #=> 1
6720-
* Date.new(2001,2,3) <=> Object.new #=> nil
6721-
* Date.new(2001,2,3) <=> Rational(4903887,2) #=> 0
6715+
* - <tt>-1</tt> if +other+ is larger.
6716+
* - <tt>0</tt> if the two are equal.
6717+
* - <tt>1</tt> if +other+ is smaller.
6718+
* - +nil+ if the two are incomparable.
6719+
*
6720+
* Argument +other+ may be:
6721+
*
6722+
* - Another \Date object:
6723+
*
6724+
* d = Date.new(2022, 7, 27) # => #<Date: 2022-07-27 ((2459788j,0s,0n),+0s,2299161j)>
6725+
* prev_date = d.prev_day # => #<Date: 2022-07-26 ((2459787j,0s,0n),+0s,2299161j)>
6726+
* next_date = d.next_day # => #<Date: 2022-07-28 ((2459789j,0s,0n),+0s,2299161j)>
6727+
* d <=> next_date # => -1
6728+
* d <=> d # => 0
6729+
* d <=> prev_date # => 1
6730+
*
6731+
* - A DateTime object:
6732+
*
6733+
* d <=> DateTime.new(2022, 7, 26) # => 1
6734+
* d <=> DateTime.new(2022, 7, 27) # => 0
6735+
* d <=> DateTime.new(2022, 7, 29) # => -1
6736+
*
6737+
* - A numeric (compares <tt>self.ajd</tt> to +other+):
6738+
*
6739+
* d <=> 2459789 # => -1
6740+
* d <=> 2459788 # => -1
6741+
* d <=> 2459787 # => 1
6742+
* d <=> d.ajd # => 0
6743+
*
6744+
* - Any other object:
6745+
*
6746+
* d <=> Object.new # => nil
67226747
*
6723-
* See also Comparable.
67246748
*/
67256749
static VALUE
67266750
d_lite_cmp(VALUE self, VALUE other)

0 commit comments

Comments
 (0)