Class Numeric
In: lib/facet/float/approx%3F.rb
lib/facet/float/round_off.rb
lib/facet/float/round_at.rb
lib/facet/float/round_to.rb
lib/facet/numeric/octet_units.rb
lib/facet/numeric/distance.rb
lib/facet/numeric/succ.rb
lib/facet/numeric/cmp.rb
lib/facet/numeric/to_b.rb
lib/facet/numeric/at_least.rb
lib/facet/numeric/at_most.rb
lib/facet/numeric/bound_by.rb
lib/facet/numeric/pred.rb
Parent: Object

Methods

approx?   at_least   at_most   bound_by   cmp   distance   octet_units   pred   round_at   round_to   succ   to_b  

External Aliases

round -> round_off
  To properly support Float’s rounding methods, Numeric must also be augmented.

Public Instance methods

To properly support Float#approx?, Numeric must also be augmented.

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.

Provides pred as the opposite of succ.

  require 'facet/numeric/succ'

  3.pred(2)  #=> 1

To properly support Float’s rounding methods, Numeric must also be augmented.

To properly support Float’s rounding methods, Numeric must also be augmented.

Allows succ to take n increments.

  require 'facet/numeric/succ'

  3.succ(2)  #=> 5

Provides a boolean interpretation of self. If self == 0 then false else true.

  require 'facet/numeric/to_b'

  0.to_b    #=> false
  1.to_b    #=> true
  2.3.to_b  #=> true

[Validate]