Comparable#clamp
to limit value to a range RB-C1019When you want to limit a value to a certain range, prefer using Comparable#clamp
intead of combinations of
min
/max
and conditionals.
[[x, low].max, high].min
if x < low
low
elsif high < x
high
else
x
end
x.clamp(low, high)