Class Integer
In: numeric.c
lib/rational.rb
Parent: Numeric

Integer is the basis for the two concrete classes that hold whole numbers, Bignum and Fixnum.

Methods

ceil   chr   denominator   downto   floor   gcd   gcd2   gcdlcm   induced_from   integer?   lcm   next   numerator   round   succ   times   to_i   to_int   to_r   truncate   upto  

Included Modules

Precision

Public Class methods

Public Instance methods

Returns a string containing the ASCII character represented by the receiver’s value.

   65.chr    #=> "A"
   ?a.chr    #=> "a"
   230.chr   #=> "\346"

In an integer, the denominator is 1. Therefore, this method returns 1.

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!

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.

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]

Always returns true.

Returns the lowest common multiple (LCM) of the two arguments (self and other).

Examples:

  6.lcm 7        # -> 42
  6.lcm 9        # -> 18

Returns the Integer equal to int + 1.

   1.next      #=> 2
   (-1).next   #=> 0

In an integer, the value is the numerator of its rational equivalent. Therefore, this method returns self.

Returns the Integer equal to int + 1.

   1.next      #=> 2
   (-1).next   #=> 0

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

Returns a Rational representation of this integer.

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
To view or add comments on this documentation, please go to the API wiki.

[Validate]