instance methods
|
+@ |
+num -> num
|
|
Unary Plus---Returns the receiver's value.
| --@ |
--num -> aNumeric
|
|
Unary Minus---Returns the receiver's value, negated.
| abs |
num.abs -> aNumeric
|
|
Returns the absolute value of num.
12.abs |
» |
12 |
(-34.56).abs |
» |
34.56 |
-34.56.abs |
» |
34.56 |
| coerce |
num.coerce( aNumeric )
-> anArray
|
|
If aNumeric is the same type as num, returns an array
containing aNumeric and num. Otherwise, returns an
array with both aNumeric and num represented as
Float objects.
1.coerce(2.5) |
» |
[2.5, 1.0] |
1.2.coerce(3) |
» |
[3.0, 1.2] |
1.coerce(2) |
» |
[2, 1] |
| divmod |
num.divmod( aNumeric )
-> anArray
|
|
Returns an array containing the quotient and modulus obtained by
dividing num by aNumeric.
If q, r = x.divmod(y) ,
q |
= |
floor(float(x) / float(y)) |
x |
= |
q * y + r |
The quotient is rounded toward -infinity. See Table
22.6 on page 355.
11.divmod(3) |
» |
[3, 2] |
11.divmod(-3) |
» |
[-4, -1] |
11.divmod(3.5) |
» |
[3.0, 0.5] |
(-11).divmod(3.5) |
» |
[-4.0, 3.0] |
(11.5).divmod(3.5) |
» |
[3.0, 1.0] |
| eql? |
num.eql?( aNumeric )
-> true or false
|
|
Returns true if num and aNumeric are the same
type and have equal values.
1 == 1.0 |
» |
true |
1.eql?(1.0) |
» |
false |
(1.0).eql?(1.0) |
» |
true |
| integer? |
num.integer? -> true or false
|
|
Returns true if num is an Integer (including
Fixnum and Bignum ).
| modulo |
num.modulo( aNumeric )
-> aNumeric
|
|
Equivalent to num.divmod( aNumeric)[1] .
| nonzero? |
num.nonzero?
-> num or nil
|
|
Returns num if num is not zero, nil otherwise. This
behavior is useful when chaining comparisons:
a = %w( z Bb bB bb BB a aA Aa AA A ) |
b = a.sort {|a,b| (a.downcase <=> b.downcase).nonzero? || a <=> b } |
b |
» |
["A", "a", "AA", "Aa", "aA", "BB", "Bb", "bB", "bb", "z"] |
| remainder |
num.remainder( aNumeric )
-> aNumeric
|
|
If num and aNumeric have different signs, returns
mod-aNumeric; otherwise, returns
mod. In both cases
mod is the value num.modulo( aNumeric) . The
differences between remainder and modulo (% ) are
shown in Table 22.6 on page 355.
| zero? |
num.zero? -> true or false
|
|
Returns true if num has a zero value.
|