### Home Classes Methods

### In Files

- lib/facets/object/dup.rb
- lib/facets/boolean.rb
- lib/facets/numeric/distance.rb
- lib/facets/numeric/round.rb
- lib/facets/numeric/positive.rb
- lib/facets/numeric/spacing.rb
- lib/facets/numeric/approx.rb
- lib/facets/numeric/length.rb
- lib/facets/kernel/blank.rb

### Parent

Object

### Methods

- #approx?
- #blank?
- #clone?
- #close?
- #distance
- #dup!
- #dup?
- #length
- #negative?
- #positive?
- #round_at
- #round_to
- #spacing
- #to_b

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Lazy
- Lazy::Future
- Lazy::Promise
- Lazy::Promise::DIVERGES
- Lazy::PromiseSafe
- Enumerable
- Enumerable::Recursor
- Method
- Method::Composition
- Module
- Module::InstanceFunction
- Array
- Binding
- Class
- Comparable
- Denumerable
- Denumerator
- Dir
- Enumerator
- Exception
- Facets
- FalseClass
- File
- FileTest
- Fixnum
- Float
- Functor
- Hash
- Indexable
- Instance
- Integer
- Kernel
- MatchData
- NA
- NilClass
- Numeric
- Object
- ObjectSpace
- Proc
- Process
- Range
- Regexp
- String
- Struct
- Symbol
- Time
- TrueClass
- UnboundMethod

No matching classes.

# Numeric

### Public Instance Methods

approx?(x, n=0.0000001) click to toggle source

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

    # File lib/facets/numeric/approx.rb, line 13
    def approx?(x, n=0.0000001)
      close?(x, n)
    end

blank?() click to toggle source

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

clone?() click to toggle source

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

close?(number, epsilon=0.01) click to toggle source

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

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

@author Gavin Sinclair

    # File lib/facets/numeric/approx.rb, line 23
    def close?(number, epsilon=0.01)
      return(self == number) if epsilon.zero?

      a, b = self.to_f, number.to_f
      if a.zero? or b.zero?
        ## There's no scale, so we can only go on difference.
        (a - b).abs < @epsilon
      else
        ## We go by ratio. The ratio of two equal numbers is one, so the ratio
        ## of two practically-equal floats will be very nearly one.
        (a/b - 1).abs < epsilon
      end
    end

distance(other) click to toggle source

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

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

dup!() click to toggle source

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

    1.dup!  #=> 1

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

dup?() click to toggle source

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

length() click to toggle source

Returns `self`, useful for polymorphic cases.

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

negative?() click to toggle source

Is a number less than zero.

    # File lib/facets/numeric/positive.rb, line 11
    def negative?
      self < 0
    end

positive?() click to toggle source

Is a number greater than zero.

    # File lib/facets/numeric/positive.rb, line 5
    def positive?
      self > 0
    end

round_at(*args) click to toggle source

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.

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

round_to(*args) click to toggle source

See Float#round_to.

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

spacing() click to toggle source

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

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

to_b() click to toggle source

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

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

[Validate]

Generated with the Darkfish Rdoc Generator 2.