Class Numeric
In: lib/core/facets/kernel/blank.rb
lib/core/facets/boolean.rb
lib/core/facets/numeric/round_to.rb
lib/core/facets/numeric/spacing.rb
lib/core/facets/numeric/distance.rb
lib/core/facets/numeric/range.rb
lib/core/facets/numeric/approx.rb
lib/core/facets/numeric/delimit.rb
lib/core/facets/numeric/length.rb
lib/core/facets/numeric/positive.rb
lib/core/facets/object/dup.rb
lib/standard/facets/random.rb
lib/standard/facets/multipliers.rb
Parent: Object

Methods

approx?   blank?   clone?   close?   delimit   distance   dup!   dup?   length   negative?   plus_or_minus   positive?   range   round_to   spacing   to_b  

Included Modules

Random::NumericExtensions Multipliers

Classes and Modules

Module Numeric::Multipliers

Public Instance methods

Determines if another number is approximately equal within a given _n_th degree. Defaults to 100ths if the degree is not specified.

Currently defaults to 1/10,000,000 if the degree is not specified. But this may change once a "most commonly useful" factor is determined.

This is the same a {close?} but has a different defualt.

@author Gavin Sinclair

Determines if another number is approximately equal within a given epsilon.

This is the same a {approx?} but has a different default. In this case it is 1/100th.

@author Gavin Sinclair

Returns a string representation of the number e.g.

  1000.delimit # => "1,000"
  1000000.delimit # => "1,000,000"
  (1000000.1234).delimit # => "1,000,000.1234"

Can take a hash of options:

  • delimiter - defaults to "," but can be any string
  • separator - defaults to "." but can be any string

    1000.delimit(:delimiter => "_") # => "1_000" (1000.00).delimit(:delimiter => ".", :separator => ",") # => "1.000,00"

Returns the distance between self an another value. This is the same as #- but it provides an alternative for common naming between variant classes.

  4.distance(3)  #=> 1

Since Numeric is immutable it cannot be duplicated. For this reason try_dup returns self.

  1.dup!  #=> 1

Returns self, useful for polymorphic cases.

Is a number less than zero.

plus_or_minus(value)

Alias for range

Is a number greater than zero.

Create a range from the number plus-or-minus a given value.

Return [Range]

Conceptually, rounding is expected to apply to floating point numbers. However it can actually be applied to pretty much any Numeric object. For example, one could round an Integer to the nearest kilo.

See Float#round_to.

Returns the size of the string representation of a numerical value.

     1.spacing   #=> 1
    10.spacing   #=> 2
   100.spacing   #=> 3
  -100.spacing   #=> 4
   1.2.spacing   #=> 3

CREDIT: Victor H. Goff III

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

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

[Validate]