Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/numeric_clip.rb

Instance Method Summary collapse

Instance Method Details

#clip(lower, upper) ⇒ Object

Raises:

  • (ArgumentError)


4
5
6
7
8
9
10
11
12
13
# File 'lib/numeric_clip.rb', line 4

def clip(lower, upper)
  raise ArgumentError, "lower(#{lower}) > upper(#{upper})" if lower > upper
  if self < lower
    lower
  elsif self > upper
    upper
  else
    self
  end
end