Class: Range
Instance Method Summary collapse
-
#bound(val) ⇒ Object
Bounds val so that first <= new_val <= last.
Instance Method Details
#bound(val) ⇒ Object
Bounds val so that first <= new_val <= last.
Returns first when val < first, last when val > last, otherwise val itself.
Raises an exception if val >= end and the range is exclusive.
12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/mug/clamp.rb', line 12 def bound val a = first return a if val < a b = last if val >= b raise ArgumentError, 'greater than or equal to the exclusive range' if exclude_end? return b end val end |