Class: Integer
- Inherits:
-
Object
- Object
- Integer
- Defined in:
- lib/antlr3/util.rb
Instance Method Summary collapse
-
#at_least(x) ⇒ Object
Returns the lower of self or x.
-
#at_most(x) ⇒ Object
Returns the greater of self or x.
-
#bound(lower, upper = nil) ⇒ Object
Returns self if above the given lower bound, or within the given lower and upper bounds, otherwise returns the the bound of which the value falls outside.
Instance Method Details
#at_least(x) ⇒ Object
Returns the lower of self or x.
4.at_least(5) #=> 5
6.at_least(5) #=> 6
CREDIT Florian Gross
112 113 114 |
# File 'lib/antlr3/util.rb', line 112 def at_least( x ) ( self >= x ) ? self : x end |
#at_most(x) ⇒ Object
Returns the greater of self or x.
4.at_most(5) #=> 4
6.at_most(5) #=> 5
CREDIT Florian Gross
123 124 125 |
# File 'lib/antlr3/util.rb', line 123 def at_most( x ) ( self <= x ) ? self : x end |
#bound(lower, upper = nil) ⇒ Object
Returns self if above the given lower bound, or within the given lower and upper bounds, otherwise returns the the bound of which the value falls outside.
4.bound(3) #=> 4
4.bound(5) #=> 5
4.bound(2,7) #=> 4
9.bound(2,7) #=> 7
1.bound(2,7) #=> 2
CREDIT Trans
140 141 142 143 144 145 |
# File 'lib/antlr3/util.rb', line 140 def bound( lower, upper=nil ) return lower if self < lower return self unless upper return upper if self > upper return self end |