Restrict a number to upper/lower bounds?
- by Amy
Is there a built-in way or a more elegant way of restricting a number num to upper/lower bounds in Ruby or in Rails?
e.g. something like:
def number_bounded (num, lower_bound, upper_bound)
return lower_bound if num < lower_bound
return upper_bound if num > upper_bound
num
end