Class: Numeric

Inherits:
Object
  • Object
show all
Defined in:
lib/magician/numeric.rb

Overview

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

Instance Method Summary collapse

Instance Method Details

#digits(selection) ⇒ Integer

Deprecated.

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

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


25
26
27
# File 'lib/magician/numeric.rb', line 25

def digits selection
  to_s[selection].to_i
end

#divisible?(n) ⇒ Boolean

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.


11
12
13
# File 'lib/magician/numeric.rb', line 11

def divisible? n
  not n.zero? and modulo(n).zero?
end

#to_degreesNumeric

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


39
40
41
# File 'lib/magician/numeric.rb', line 39

def to_degrees
  self * 180 / Math::PI
end

#to_radiansNumeric

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


32
33
34
# File 'lib/magician/numeric.rb', line 32

def to_radians
  self * Math::PI / 180
end