Methods
Class
Visibility | Signature |
---|---|
public | from_prime_division (pd) |
public | induced_from (p1) |
Instance
Visibility | Signature |
---|---|
public | ceil () |
public | chr () |
public | denominator () |
public | denominator () |
public | downto (p1) |
public | even? () |
public | floor () |
public | gcd (other) |
public | gcd (other) |
public | gcd2 (int) |
public | gcdlcm (other) |
public | integer? () |
public | lcm (other) |
public | lcm (other) |
public | next () |
public | numerator () |
public | numerator () |
public | odd? () |
public | ord () |
public | pred () |
public | prime_division () |
public | round () |
public | succ () |
public | times () |
public | to_i () |
public | to_int () |
public | to_r () |
public | to_yaml ( opts = {} ) |
public | truncate () |
public | upto (p1) |
Class Method Detail
from_prime_division(pd)
Integer.induced_from(obj) => fixnum, bignum
Convert obj to an Integer.
Instance Method Detail
int.to_i => int
int.to_int => int
int.floor => int
int.ceil => int
int.round => int
int.truncate => int
As int is already an Integer, all these methods simply return the receiver.
int.chr => string
Returns a string containing the ASCII character represented by the receiver‘s value.
65.chr #=> "A" ?a.chr #=> "a" 230.chr #=> "\346"
denominator()
In an integer, the denominator is 1. Therefore, this method returns 1.
denominator()
int.downto(limit) {|i| block } => int
Iterates block, passing decreasing values from int down to and including limit.
5.downto(1) { |n| print n, ".. " } print " Liftoff!\n"
produces:
5.. 4.. 3.. 2.. 1.. Liftoff!
int.even? → true or false
Returns true if int is an even number.
int.to_i => int
int.to_int => int
int.floor => int
int.ceil => int
int.round => int
int.truncate => int
As int is already an Integer, all these methods simply return the receiver.
gcd(other)
gcd(other)
Returns the greatest common denominator of the two numbers (self and n).
Examples:
72.gcd 168 # -> 24 19.gcd 36 # -> 1
The result is positive, no matter the sign of the arguments.
gcd2(int)
gcdlcm(other)
Returns the GCD and the LCM (see gcd and lcm) of the two arguments (self and other). This is more efficient than calculating them separately.
Example:
6.gcdlcm 9 # -> [3, 18]
int.integer? → true
Always returns true.
lcm(other)
lcm(other)
Returns the lowest common multiple (LCM) of the two arguments (self and other).
Examples:
6.lcm 7 # -> 42 6.lcm 9 # -> 18
int.next => integer
int.succ => integer
Returns the Integer equal to int + 1.
1.next #=> 2 (-1).next #=> 0
numerator()
In an integer, the value is the numerator of its rational equivalent. Therefore, this method returns self.
numerator()
int.odd? → true or false
Returns true if int is an odd number.
int.ord => int
Returns the int itself.
?a.ord #=> 97
This method is intended for compatibility to character constant in Ruby 1.9. For example, ?a.ord returns 97 both in 1.8 and 1.9.
int.pred => integer
Returns the Integer equal to int - 1.
1.pred #=> 0 (-1).pred #=> -2
prime_division()
int.to_i => int
int.to_int => int
int.floor => int
int.ceil => int
int.round => int
int.truncate => int
As int is already an Integer, all these methods simply return the receiver.
int.next => integer
int.succ => integer
Returns the Integer equal to int + 1.
1.next #=> 2 (-1).next #=> 0
int.times {|i| block } => int
Iterates block int times, passing in values from zero to int - 1.
5.times do |i| print i, " " end
produces:
0 1 2 3 4
int.to_i => int
int.to_int => int
int.floor => int
int.ceil => int
int.round => int
int.truncate => int
As int is already an Integer, all these methods simply return the receiver.
int.to_i => int
int.to_int => int
int.floor => int
int.ceil => int
int.round => int
int.truncate => int
As int is already an Integer, all these methods simply return the receiver.
to_r()
Returns a Rational representation of this integer.
to_yaml( opts = {} )
int.to_i => int
int.to_int => int
int.floor => int
int.ceil => int
int.round => int
int.truncate => int
As int is already an Integer, all these methods simply return the receiver.
int.upto(limit) {|i| block } => int
Iterates block, passing in integer values from int up to and including limit.
5.upto(10) { |i| print i, " " }
produces:
5 6 7 8 9 10