Class: Numeric
- Inherits:
-
Object
- Object
- Numeric
- Defined in:
- lib/magician/numeric.rb
Overview
Magician’s extensions to the Numeric class (affects Integers and Floats).
Instance Method Summary collapse
-
#digits(selection) ⇒ Integer
Performs to_s.to_i on the number.
-
#divisible?(n) ⇒ Boolean
Returns true if the number is evenly divisible by n.
Instance Method Details
#digits(selection) ⇒ Integer
Performs to_s.to_i on the number. Note that for floats, the decimal counts as a digit within the string. TODO: Let this intelligently convert back to an Integer or Float.
use anything that works with the [] syntax)
Integer
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 14 |
# File 'lib/magician/numeric.rb', line 11 def divisible? n return false if n.zero? (self % n).zero? end |