class Numeric

Magician's extensions to the Numeric class (affects Integers and Floats).

Public Instance Methods

digits(selection) click to toggle source

Performs to_s.to_i on the number. Note that for floats, the decimal counts as a digit within the string.

@param [Range] selection the selection/range to get from the number (you can

use anything that works with the [] syntax)

@return [Integer] substring of the number (using []), converted to an

Integer

@deprecated Avoid using this any more. It's inaccurate and not very useful.

# File lib/magician/numeric.rb, line 25
def digits selection
  to_s[selection].to_i
end
divisible?(n) click to toggle source

Returns true if the number is evenly divisible by n. If n is equal to 0, it returns false, since numbers cannot be divided by 0 in real number arithmetic.

@param [Numeric] n the number that this number (self) should be divided by

@return [Boolean] true if the number is evenly divisible by n

# File lib/magician/numeric.rb, line 11
def divisible? n
  n.zero? ? false : modulo(n).zero?
end
to_degrees() click to toggle source

Converts the number from radians to degrees and returns the result.

@return [Numeric] the number in degrees

# File lib/magician/numeric.rb, line 39
def to_degrees
  self * 180 / Math::PI
end
to_radians() click to toggle source

Converts the number from degrees to radians and returns the result.

@return [Numeric] the number in radians

# File lib/magician/numeric.rb, line 32
def to_radians
  self * Math::PI / 180
end