Class: Numeric

Inherits:
Object show all
Defined in:
lib/rbot/core/utils/extends.rb

Overview

Extensions for the Numeric classes

Instance Method Summary collapse

Instance Method Details

#clip(left, right = 0) ⇒ Object

This method forces a real number to be not more than a given positive number or not less than a given positive number, or between two any given numbers

Raises:

  • (ArgumentError)


195
196
197
198
199
200
201
202
# File 'lib/rbot/core/utils/extends.rb', line 195

def clip(left,right=0)
  raise ArgumentError unless left.kind_of?(Numeric) and right.kind_of?(Numeric)
  l = [left,right].min
  u = [left,right].max
  return l if self < l
  return u if self > u
  return self
end