From 55eb0d5c780e65139911569cc470b82b0c3b39a0 Mon Sep 17 00:00:00 2001 From: Kouhei Yanagita Date: Wed, 12 Apr 2023 09:49:47 +0900 Subject: [PATCH] [DOC] Add doc for behavior when passing nil to Comparable#clamp(min, max) --- compar.c | 6 ++++++ 1 file changed, 6 insertions(+) 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 (range) form, returns _range.begin_ if _obj_ * <=> _range.begin_ is less than zero, _range.end_ * if _obj_ <=> _range.end_ is greater than zero, and