From 33bf027d79901575c0ea2ab407b4a1ec368420dd Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sun, 17 Jul 2022 18:52:59 +0900 Subject: [PATCH] mruby-compar-ext/compar.rb (clamp): support endless/beginless range. Ref #5748 --- mrbgems/mruby-compar-ext/mrblib/compar.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/mrbgems/mruby-compar-ext/mrblib/compar.rb b/mrbgems/mruby-compar-ext/mrblib/compar.rb index 1f89e6439..0ea3d190b 100644 --- a/mrbgems/mruby-compar-ext/mrblib/compar.rb +++ b/mrbgems/mruby-compar-ext/mrblib/compar.rb @@ -14,11 +14,16 @@ module Comparable def clamp(min, max=nil) if max.nil? if min.kind_of?(Range) - if min.exclude_end? + max = min.begin + if max.nil? + max = self + elsif min.exclude_end? raise ArgumentError, "cannot clamp with an exclusive range" end - max = min.max - min = min.min + min = min.end + if min.nil? + min = self + end else raise TypeError, "wrong argument type #{min.class}" end