Subclasses: Bignum, Fixnum
Integer
is the basis for the two concrete classes that hold whole numbers, Bignum
and Fixnum
.
65.chr → "A"
?a.chr → "a"
230.chr → "\346"
5.downto(1) { |n| print n, ".. " }
print " Liftoff!\n"
produces:
5.. 4.. 3.. 2.. 1.. Liftoff!
true
true
.
Integer
equal to int + 1.
1.next → 2
(-1).next → 0
1.step(10, 2) { |i| print i, " " }
produces:
1 3 5 7 9
Integer#next
.
5.times do |i|
print i, " "
end
print "\n"
produces:
0 1 2 3 4
5.upto(10) { |i| print i, " " }
produces:
5 6 7 8 9 10
Extracted from the book "Programming Ruby - The Pragmatic Programmer's Guide"
Copyright © 2001 by Addison Wesley Longman, Inc. This material may be distributed only subject to the terms and conditions set forth in the Open Publication License, v1.0 or later (the latest version is presently available at http://www.opencontent.org/openpub/).
Distribution of substantively modified versions of this document is prohibited without the explicit permission of the copyright holder.
Distribution of the work or derivative of the work in any standard (paper) book form is prohibited unless prior permission is obtained from the copyright holder.