mruby-compar-ext/compar.rb: Comparable#clamp to accept nil as arguments

This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-04-13 21:37:40 +09:00
parent 68c58eac91
commit 836bebc708
+10 -1
View File
@@ -53,8 +53,17 @@ module Comparable
if min.nil?
min = self
end
elsif min.nil? or min < self
return self
else
raise TypeError, "wrong argument type #{min.class}"
return min
end
end
if min.nil?
if self < max
return self
else
return max
end
end
c = min <=> max