def restrict(value, range)
      [[value, range.first].max, range.last].min
    end
def restrict(value, range)
      [[value, range.first].max, range.last].min
    end
Restricts a number to falling within a given range.
 Returns the number if it falls within the range,
 or the closest value in the range if it doesn't.

 @param value [Numeric]
 @param range [Range<Numeric>]
 @return [Numeric]