mruby-compar-ext/compar.rb (clamp): support endless/beginless range.

Ref #5748
This commit is contained in:
Yukihiro "Matz" Matsumoto
2022-07-17 18:52:59 +09:00
parent b1bfa1d5c8
commit 33bf027d79
+8 -3
View File
@@ -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