summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeremy Evans <code@jeremyevans.net>2020-09-01 09:58:45 -0700
committerJeremy Evans <code@jeremyevans.net>2020-09-01 10:52:47 -0700
commitde10a1f3583adeeffd7f8bcf8f276e0a626ffa0c (patch)
tree5a36183a8a224f300b6b4e7917cd7b848d95f9e0
parent4db4faef0f96bfd3504f5eac454a0308c618ccd6 (diff)
Update documentation for Range#max
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3500
-rw-r--r--range.c36
1 files changed, 28 insertions, 8 deletions
diff --git a/range.c b/range.c
index 5e1103ce578..59d8aefb23b 100644
--- a/range.c
+++ b/range.c
@@ -1200,14 +1200,34 @@ range_min(int argc, VALUE *argv, VALUE range)
* rng.max(n) -> obj
* rng.max(n) {| a,b | block } -> obj
*
- * Returns the maximum value in the range. Returns +nil+ if the begin
- * value of the range larger than the end value. Returns +nil+ if
- * the begin value of an exclusive range is equal to the end value.
- *
- * Can be given an optional block to override the default comparison
- * method <code>a <=> b</code>.
- *
- * (10..20).max #=> 20
+ * Returns the maximum value in the range, or an array of maximum
+ * values in the range if given an \Integer argument.
+ *
+ * For inclusive ranges with an end, the maximum value of the range
+ * is the same as the end of the range.
+ *
+ * If an argument or block is given, or +self+ is an exclusive,
+ * non-numeric range, calls Enumerable#max (via +super+) with the
+ * argument and/or block to get the maximum values, unless +self+ is
+ * a beginless range, in which case it raises a RangeError.
+ *
+ * If +self+ is an exclusive, integer range (both start and end of the
+ * range are integers), and no arguments or block are provided, returns
+ * last value in the range (1 before the end). Otherwise, if +self+ is
+ * an exclusive, numeric range, raises a TypeError.
+ *
+ * Returns +nil+ if the begin value of the range larger than the
+ * end value. Returns +nil+ if the begin value of an exclusive
+ * range is equal to the end value. Raises a RangeError if called on
+ * an endless range.
+ *
+ * Examples:
+ * (10..20).max #=> 20
+ * (10..20).max(2) #=> [20, 19]
+ * (10...20).max #=> 19
+ * (10...20).max(2) #=> [19, 18]
+ * (10...20).max{|x, y| -x <=> -y } #=> 10
+ * (10...20).max(2){|x, y| -x <=> -y } #=> [10, 11]
*/
static VALUE