Returns the lower of self or x.
require 'facet/numeric/bound_by' 4.at_least(5) #=> 5 6.at_least(5) #=> 6
Returns the greater of self or x.
require 'facet/numeric/bound_by' 4.at_most(5) #=> 4 6.at_most(5) #=> 5
Returns the value or the given upper or lower bound if the value falls outside of them.
require 'facet/comparable/bound_by' 4.bound_by(2,7) #=> 4 9.bound_by(2,7) #=> 7 1.bound_by(2,7) #=> 2
Alternate for comparison operator #<=>.
require 'facet/numeric/succ' 3.cmp(1) #=> 1 3.cmp(3) #=> 0 3.cmp(10) #=> -1
Returns the distance between self an another value. This is the same as #- but it provides an alternative for common naming between variant classes.
require 'facet/numeric/distance' 4.distance(3) #=> 1
Provides formated output of bytes proportial size.
require 'facet/numeric/octet_units' 1024.octet_units #=> "1.00 KB" 1048576.octet_units #=> "1.00 MB" 1073741824.octet_units #=> "1.00 GB" 1099511627776.octet_units #=> "1.00 TB"
Takes a format string to adjust output.
1024.octet_units('%.0f') #=> "1 KB"
Note: the name of this method will likely change in the future. But the best name has yet to be determined at this point.