class Range

Public Instance Methods

bound(val) click to toggle source

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.

# File lib/mug/clamp.rb, line 30
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