Class Numeric
In: lib/facets/core/facets/object/dup.rb
lib/facets/core/facets/kernel/blank.rb
lib/facets/core/facets/numeric/round.rb
lib/facets/core/facets/numeric/spacing.rb
lib/facets/core/facets/numeric/distance.rb
lib/facets/core/facets/numeric/approx.rb
lib/facets/core/facets/numeric/length.rb
lib/facets/core/facets/boolean.rb
Parent: Object

Methods

approx?   blank?   clone?   distance   dup!   dup?   length   round_at   round_to   spacing   to_b  

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.

CREDIT: Trans

[Source]

# File lib/facets/core/facets/numeric/approx.rb, line 9
  def approx?(x, n=0.01)
    return(self == x) if n == 0
    (self - x).abs <= n
  end

[Source]

# File lib/facets/core/facets/kernel/blank.rb, line 80
  def blank?
    false
  end

[Source]

# File lib/facets/core/facets/object/dup.rb, line 78
  def clone? ; false ; end

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

[Source]

# File lib/facets/core/facets/numeric/distance.rb, line 9
  def distance(other)
    self - other
  end

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

  1.dup!  #=> 1

[Source]

# File lib/facets/core/facets/object/dup.rb, line 76
  def dup!   ; self  ; end

[Source]

# File lib/facets/core/facets/object/dup.rb, line 77
  def dup?   ; false ; end

Returns self, useful for polymorphic cases.

[Source]

# File lib/facets/core/facets/numeric/length.rb, line 5
  def length
    self
  end

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_at.

[Source]

# File lib/facets/core/facets/numeric/round.rb, line 9
  def round_at(*args)
    to_f.round_at(*args)
  end

See Float#round_to.

[Source]

# File lib/facets/core/facets/numeric/round.rb, line 15
  def round_to(*args)
    to_f.round_to(*args)
  end

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

[Source]

# File lib/facets/core/facets/numeric/spacing.rb, line 14
  def spacing
    to_s.length
  end

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

[Source]

# File lib/facets/core/facets/boolean.rb, line 64
  def to_b
    self == 0 ? false : true
  end

[Validate]