Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/casual_support/numeric/constrain.rb,
lib/casual_support/numeric/at_least_most.rb
Instance Method Summary collapse
-
#at_least(limit) ⇒ Numeric
Enforces a lower bound for a number.
-
#at_most(limit) ⇒ Numeric
(also: #cap)
Enforces an upper bound for a number.
-
#constrain(low, high) ⇒ Numeric
(also: #clamp)
Constrains a number to a closed interval.
Instance Method Details
#at_least(limit) ⇒ Numeric
Enforces a lower bound for a number.
7 8 9 |
# File 'lib/casual_support/numeric/at_least_most.rb', line 7 def at_least(limit) self < limit ? limit : self end |
#at_most(limit) ⇒ Numeric Also known as: cap
Enforces an upper bound for a number.
15 16 17 |
# File 'lib/casual_support/numeric/at_least_most.rb', line 15 def at_most(limit) self > limit ? limit : self end |
#constrain(low, high) ⇒ Numeric Also known as: clamp
Constrains a number to a closed interval.
8 9 10 11 12 |
# File 'lib/casual_support/numeric/constrain.rb', line 8 def constrain(low, high) return low if self < low return high if self > high self end |