Returns the lower of self or x.
4.at_least(5) #=> 5 6.at_least(5) #=> 6
CREDIT: Florian Gross
# File lib/core/facets/comparable/cap.rb, line 10 10: def at_least(lower) 11: (self >= lower) ? self : lower 12: end
Returns the greater of self or x.
4.at_most(5) #=> 4 6.at_most(5) #=> 5
CREDIT: Florian Gross
# File lib/core/facets/comparable/cap.rb, line 21 21: def at_most(upper) 22: (self <= upper) ? self : upper 23: end
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: Florian Gross
Returns the greater of self or x.
4.cap(5) #=> 4 6.cap(5) #=> 5
CREDIT: Trans
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.clip(3) #=> 4 4.clip(5) #=> 5 4.clip(2,7) #=> 4 9.clip(2,7) #=> 7 1.clip(2,7) #=> 2
CREDIT Florian Gross, Trans
# File lib/core/facets/comparable/clip.rb, line 16 16: def clip(lower, upper=nil) 17: return lower if self < lower 18: return self unless upper 19: return upper if self > upper 20: return self 21: end
Alternate name for comparison operator #<=>.
3.cmp(1) #=> 1 3.cmp(3) #=> 0 3.cmp(10) #=> -1
This fundamental compare method is used to keep comparison compatible with #.
CREDIT: Peter Vanbroekhoven
# File lib/core/facets/comparable/cmp.rb, line 14 14: def cmp(o) 15: self<=>o 16: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.