Sha256: b21cc5d8126de57fed3deecd4bee59314e11b1a4f7523b58aa16a4691679b6df
Contents?: true
Size: 419 Bytes
Versions: 14
Compression:
Stored size: 419 Bytes
Contents
module MoreCoreExtensions module NumericClamp # # Clamp a number to a minimum and/or maximum value. # # 8.clamp(nil, nil) #=> 8 # 8.clamp(9, nil) #=> 9 # 8.clamp(nil, 6) #=> 6 def clamp(min, max) value = self value = [value, min].max if min value = [value, max].min if max value end end end Numeric.send(:prepend, MoreCoreExtensions::NumericClamp)
Version data entries
14 entries across 14 versions & 1 rubygems