Follow Techotopia on Twitter

On-line Guides
All Guides
eBook Store
iOS / Android
Linux for Beginners
Office Productivity
Linux Installation
Linux Security
Linux Utilities
Linux Virtualization
Linux Kernel
System/Network Admin
Programming
Scripting Languages
Development Tools
Web Development
GUI Toolkits/Desktop
Databases
Mail Systems
openSolaris
Eclipse Documentation
Techotopia.com
Virtuatopia.com

How To Guides
Virtualization
General System Admin
Linux Security
Linux Filesystems
Web Servers
Graphics & Desktop
PC Hardware
Windows
Problem Solutions
Privacy Policy

  




 

 

Ruby Programming
Previous Page Home Next Page
class Integer
Parent: Numeric
Version: 1.6

Index:

chr downto integer? next step succ times upto



Subclasses: Bignum, Fixnum

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

instance methods
chr int.chr -> aString

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

65.chr "A"
?a.chr "a"
230.chr "\346"

downto int.downto( anInteger ) {| i | block }

-> int

Iterates block, passing decreasing values from int down to and including anInteger.

5.downto(1) { |n| print n, ".. " }
print "  Liftoff!\n"
produces:
5.. 4.. 3.. 2.. 1..   Liftoff!

integer? int.integer? -> true

Always returns true.

next int.next -> anInteger

Returns the Integer equal to int + 1.

1.next 2
(-1).next 0

step int.step( endNum, step ) {| i | block }

-> int

Invokes block with the sequence of numbers starting at int, incremented by step on each call. The loop finishes when the value to be passed to the block is greater than endNum (if step is positive) or less than endNum (if step is negative).

1.step(10, 2) { |i| print i, " " }
produces:
1 3 5 7 9

succ int.succ -> anInteger

Synonym for Integer#next .

times int.times {| i | block }

-> int

Iterates block int times, passing in values from zero to int - 1.

5.times do |i|
  print i, " "
end
print "\n"
produces:
0 1 2 3 4

upto int.upto( anInteger ) {| i | block }

-> int

Iterates block, passing in integer values from int up to and including anInteger.

5.upto(10) { |i| print i, " " }
produces:
5 6 7 8 9 10


Ruby Programming
Previous Page Home Next Page

 
 
  Published under the terms of the Open Publication License Design by Interspire