summaryrefslogtreecommitdiff
path: root/compar.c
diff options
context:
space:
mode:
authorKouhei Yanagita <yanagi@shakenbu.org>2023-04-12 09:49:47 +0900
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2023-10-25 16:34:37 +0900
commit55eb0d5c780e65139911569cc470b82b0c3b39a0 (patch)
treeb333aac4d67caaf6025950ede68e2d8f4661f928 /compar.c
parent3e64cf60b5162bb5dad772f300b7f6346e5f83f9 (diff)
[DOC] Add doc for behavior when passing nil to Comparable#clamp(min, max)
Diffstat (limited to 'compar.c')
-rw-r--r--compar.c6
1 files changed, 6 insertions, 0 deletions
diff --git a/compar.c b/compar.c
index 2b34ebb062..2f62455a0e 100644
--- a/compar.c
+++ b/compar.c
@@ -187,6 +187,12 @@ cmp_between(VALUE x, VALUE min, VALUE max)
* 'd'.clamp('a', 'f') #=> 'd'
* 'z'.clamp('a', 'f') #=> 'f'
*
+ * If _min_ is +nil+, it is considered smaller than _obj_,
+ * and if _max_ is +nil+, it is considered greater than _obj_.
+ *
+ * -20.clamp(0, nil) #=> 0
+ * 523.clamp(nil, 100) #=> 100
+ *
* In <code>(range)</code> form, returns _range.begin_ if _obj_
* <code><=></code> _range.begin_ is less than zero, _range.end_
* if _obj_ <code><=></code> _range.end_ is greater than zero, and