Class Integer
In: numeric.c
lib/mathn.rb
lib/yaml/rubytypes.rb

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

Methods

ceil   chr   downto   even?   floor   from_prime_division   gcd   induced_from   integer?   next   odd?   pred   prime_division   succ   times   to_i   to_int   to_yaml   truncate   upto  

Included Modules

Precision

Public Class methods

Public Instance methods

Returns a string containing the character represented by the receiver‘s value according to encoding.

   65.chr    #=> "A"
   230.chr   #=> "\346"
   255.chr(Encoding::UTF_8)   #=> "\303\277"

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 true if int is an even number.

Always returns true.

Returns the Integer equal to int + 1.

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

Returns true if int is an odd number.

Returns the Integer equal to int - 1.

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

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

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

[Validate]

ruby-doc.org is hosted and maintained by James Britt and Happy Camper Studios, a Ruby application development company in Phoenix, Arizona. The site was created in 2002 as part of the Ruby Documentation Project to promote the Ruby language and to help other Ruby hackers.

Documentation content on ruby-doc.org is provided by remarkable members of the Ruby community.

For more information on the Ruby programming language, visit ruby-lang.org.

Want to help improve Ruby's API docs? See Ruby Documentation Guidelines.