1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223
|
<ppdoc>
<copyright>
Copyright (c) 2001 by Addison Wesley Longman. 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/).
</copyright>
<class name="Integer" super="Numeric" type="class"> <subclasses>Bignum, Fixnum</subclasses>
<p/>
<classname>Integer</classname> is the basis for the two concrete classes that hold
whole numbers, <classname>Bignum</classname> and <classname>Fixnum</classname>.
<p/>
<methods type="instance">
<method name="chr" ref="chr">
<callseq>
<obj>int</obj>.chr <returns><obj>aString</obj></returns>
</callseq>
<desc>
<p/>
Returns a string containing the ASCII character represented by
the receiver's value.
<p/>
<codefragment>
<fullcode><![CDATA[ 65.chr
?a.chr
230.chr
]]></fullcode><rubycode>
<tr>
<td><tt>65.chr</tt></td>
<td>»</td>
<td><tt>"A"</tt></td>
</tr>
<tr>
<td><tt>?a.chr</tt></td>
<td>»</td>
<td><tt>"a"</tt></td>
</tr>
<tr>
<td><tt>230.chr</tt></td>
<td>»</td>
<td><tt>"\346"</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="downto" ref="downto">
<callseq>
<obj>int</obj>.downto( <obj>anInteger</obj> ) <block>{| i | <blockbody>block</blockbody> }</block>
<p/>
<returns><obj>int</obj></returns>
</callseq>
<desc>
<p/>
Iterates <em>block</em>, passing decreasing values
from <obj>int</obj> down to and including <obj>anInteger</obj>.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[ 5.downto(1) { |n| print n, ".. " }
print " Liftoff!\n"
]]></fullcode>
5.downto(1)<nbsp/>{<nbsp/>|n|<nbsp/>print<nbsp/>n,<nbsp/>"..<nbsp/>"<nbsp/>}
print<nbsp/>"<nbsp/><nbsp/>Liftoff!\n"
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
5..<nbsp/>4..<nbsp/>3..<nbsp/>2..<nbsp/>1..<nbsp/><nbsp/><nbsp/>Liftoff!
</alltt>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="integer?" ref="integer_qm">
<callseq>
<obj>int</obj>.integer? <returns><const>true</const></returns>
</callseq>
<desc>
<p/>
Always returns <const>true</const>.
<p/>
</desc>
</method>
<p/>
<method name="next" ref="next">
<callseq>
<obj>int</obj>.next <returns><obj>anInteger</obj></returns>
</callseq>
<desc>
<p/>
Returns the <classname>Integer</classname> equal to <obj>int</obj><nbsp/>+<nbsp/>1.
<p/>
<codefragment>
<fullcode><![CDATA[ 1.next
(-1).next
]]></fullcode><rubycode>
<tr>
<td><tt>1.next</tt></td>
<td>»</td>
<td><tt>2</tt></td>
</tr>
<tr>
<td><tt>(-1).next</tt></td>
<td>»</td>
<td><tt>0</tt></td>
</tr>
</rubycode>
<p/>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="step" ref="step">
<callseq>
<obj>int</obj>.step( <obj>endNum</obj>, <obj>step</obj> ) <block>{| i | <blockbody>block</blockbody> }</block>
<p/>
<returns><obj>int</obj></returns>
</callseq>
<desc>
<p/>
Invokes <em>block</em> with the sequence of numbers starting at
<obj>int</obj>,
incremented by <obj>step</obj> on each call. The loop
finishes when the value to be passed to the block is greater
than <obj>endNum</obj> (if <obj>step</obj> is positive) or less than
<obj>endNum</obj> (if <obj>step</obj> is negative).
<p/>
<codefragment>
<alltt><fullcode><![CDATA[ 1.step(10, 2) { |i| print i, " " }
!- print "\n"
]]></fullcode>
1.step(10,<nbsp/>2)<nbsp/>{<nbsp/>|i|<nbsp/>print<nbsp/>i,<nbsp/>"<nbsp/>"<nbsp/>}
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
1<nbsp/>3<nbsp/>5<nbsp/>7<nbsp/>9
</alltt>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="succ" ref="succ">
<callseq>
<obj>int</obj>.succ <returns><obj>anInteger</obj></returns>
</callseq>
<desc>
<p/>
Synonym for <cim><file>integer</file><front>Integer</front><back>next</back><mref>next</mref></cim>.
<p/>
</desc>
</method>
<p/>
<method name="times" ref="times">
<callseq>
<obj>int</obj>.times <block>{| i | <blockbody>block</blockbody> }</block>
<p/>
<returns><obj>int</obj></returns>
</callseq>
<desc>
<p/>
Iterates block <obj>int</obj> times, passing in values from zero to
<obj>int</obj> - 1.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[ 5.times do |i|
print i, " "
end
print "\n"
]]></fullcode>
5.times<nbsp/>do<nbsp/>|i|
<nbsp/><nbsp/>print<nbsp/>i,<nbsp/>"<nbsp/>"
end
print<nbsp/>"\n"
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
0<nbsp/>1<nbsp/>2<nbsp/>3<nbsp/>4
</alltt>
</codefragment>
<p/>
</desc>
</method>
<p/>
<method name="upto" ref="upto">
<callseq>
<obj>int</obj>.upto( <obj>anInteger</obj> ) <block>{| i | <blockbody>block</blockbody> }</block>
<p/>
<returns><obj>int</obj></returns>
</callseq>
<desc>
<p/>
Iterates <em>block</em>, passing in integer values from
<obj>int</obj> up to and including <obj>anInteger</obj>.
<p/>
<codefragment>
<alltt><fullcode><![CDATA[ 5.upto(10) { |i| print i, " " }
!- print "\n"
]]></fullcode>
5.upto(10)<nbsp/>{<nbsp/>|i|<nbsp/>print<nbsp/>i,<nbsp/>"<nbsp/>"<nbsp/>}
</alltt>
</codefragment>
<em>produces:</em>
<codefragment><alltt>
5<nbsp/>6<nbsp/>7<nbsp/>8<nbsp/>9<nbsp/>10
</alltt>
</codefragment>
<p/>
</desc>
</method>
<p/>
</methods>
<p/>
</class>
</ppdoc>
|