Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- /home/apoc/projects/ruby/rbot/lib/rbot/core/utils/extends.rb
Overview
Extensions for the Numeric classes
Instance Method Summary (collapse)
-
- (Object) clip(left, right = 0)
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.
Instance Method Details
- (Object) clip(left, right = 0)
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
206 207 208 209 210 211 212 213 |
# File '/home/apoc/projects/ruby/rbot/lib/rbot/core/utils/extends.rb', line 206 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 |