Sha256: a9f6dd3e4c7d4f196d4557d6db321437ae6da83a2f3fed5089f72d1fa6fda818
Contents?: true
Size: 420 Bytes
Versions: 19
Compression:
Stored size: 420 Bytes
Contents
Numeric.class_eval do # # Coerce a number to lie between min and max. # # @example # 5.clamp(6, 7) # => 6 # 5.clamp(6) # => 6 # 5.clamp(nil, 6) # => 5 # 5.clamp(nil, 4) # => 4 # def clamp min=nil, max=nil raise ArgumentError, "min must be <= max" if (min && max && (min > max)) return min if min && (self < min) return max if max && (self > max) self end end
Version data entries
19 entries across 19 versions & 1 rubygems