Skip to content

Commit 836bebc

Browse files
committed
mruby-compar-ext/compar.rb: Comparable#clamp to accept nil as arguments
1 parent 68c58ea commit 836bebc

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

mrbgems/mruby-compar-ext/mrblib/compar.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,17 @@ def clamp(min, max=nil)
5353
if min.nil?
5454
min = self
5555
end
56+
elsif min.nil? or min < self
57+
return self
5658
else
57-
raise TypeError, "wrong argument type #{min.class}"
59+
return min
60+
end
61+
end
62+
if min.nil?
63+
if self < max
64+
return self
65+
else
66+
return max
5867
end
5968
end
6069
c = min <=> max

0 commit comments

Comments
 (0)