Module: Comparable

Defined in:
lib/casual_support/comparable/at_most.rb,
lib/casual_support/comparable/at_least.rb

Instance Method Summary collapse

Instance Method Details

#at_least(limit) ⇒ Comparable

Enforces a lower bound for the value.

Examples:

-10.at_least(0)  # == 0
99.at_least(0)   # == 99

Parameters:

Returns:



11
12
13
# File 'lib/casual_support/comparable/at_least.rb', line 11

def at_least(limit)
  self < limit ? limit : self
end

#at_most(limit) ⇒ Comparable Also known as: cap

Enforces an upper bound for the value.

Examples:

120.at_most(100)  # == 100
90.at_most(100)   # == 90

Parameters:

Returns:



11
12
13
# File 'lib/casual_support/comparable/at_most.rb', line 11

def at_most(limit)
  self > limit ? limit : self
end