Module: Polyfill::V2_4::Comparable::Instance::Clamp::Method

Defined in:
lib/polyfill/v2_4/comparable/instance/clamp.rb

Instance Method Summary collapse

Instance Method Details

#clamp(min, max) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/polyfill/v2_4/comparable/instance/clamp.rb', line 7

def clamp(min, max)
  if min > max
    raise ArgumentError, 'min argument must be smaller than max argument'
  end

  return min if min > self
  return max if max < self
  self
end