class Numeric
Public Instance Methods
approx?(x, n=0.01)
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.
CREDIT: Trans
# File lib/core/facets/numeric/approx.rb, line 9 def approx?(x, n=0.01) return(self == x) if n == 0 (self - x).abs <= n end
blank?()
click to toggle source
# File lib/core/facets/blank.rb, line 56 def blank? false end
clone?()
click to toggle source
# File lib/core/facets/duplicable.rb, line 30 def clone? ; false ; 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/core/facets/numeric/distance.rb, line 9 def distance(other) self - other end
dup?()
click to toggle source
# File lib/core/facets/duplicable.rb, line 29 def dup? ; false ; 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 and Numeric object. For example, one could round an Integer to the nearest kilo. So the actual round.rb lib is in the numeric folder, but we'll add this here for convenience.
See Float#round_at.
# File lib/core/facets/numeric/round.rb, line 11 def round_at(*args) to_f.round_at(*args) end
round_to(*args)
click to toggle source
See Float#round_to.
# File lib/core/facets/numeric/round.rb, line 17 def round_to(*args) to_f.round_to(*args) 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/core/facets/boolean.rb, line 76 def to_b self == 0 ? false : true end