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 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323
|
<html><title>Programming Ruby: The Pragmatic Programmer's Guide</title><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><STYLE TYPE="text/css"><!--
BODY { margin-left: 1in;
width: 6in;
font-family: helvetica, arial, sans-serif;
}
H1 { color: #000080;
font-family: helvetica, arial, sans-serif;
font-size: 22pt;
margin-left: 0in
}
H2 { color: #000080; font: bold x-large helvetica, sans-serif;
margin-left: 0in }
H3 { color: #000080; font: bold large helvetica, sans-serif; }
H4 { color: #000080; font: italic large helvetica, sans-serif; }
.ruby { background: #fff0f0 }
.header { color: white }
.subheader { color: #ffdddd }
.sidebar { width: 6in }
span.sans { font-family: helvetica, arial, sans-serif }
-->
</STYLE><table bgcolor="#a03030" cellpadding="3" border="0" cellspacing="0"><tr><td colspan="3"><table bgcolor="#902020" cellpadding="20"><tr><td><h1 class="header">Programming Ruby</h1><h3 class="subheader">The Pragmatic Programmer's Guide</h3></td></tr></table></td></tr><tr><td width="33%" align="left"><a class="subheader" href="builtins.html">Previous <</a></td><td width="33%" align="center" valign="middle"><a class="subheader" href="index.html">Contents ^</a><br></td><td width="33%" align="right"><a class="subheader" href="lib_patterns.html">Next ></a><br></td></tr></table></head><body bgcolor="white">
<!--
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/).
-->
<h1>Standard Library</h1><hr><br>
<P></P>
Ruby comes ``out of the box'' with a large and useful library of
modules and classes. This chapter contains a sampling of the more
useful of these.
<P></P>
Interestingly, and unlike some of the code in later chapters, all of
these libraries are written in Ruby. You'll find the source in the
<code>lib</code> subdirectory of the standard Ruby distribution.
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class Complex</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Numeric</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#new">new</a> <a href="#Arithmeticoperations"><i>Arithmetic operations</i></a> <a href="#_lt_eq_lt"><i><=></i></a> <a href="#_eq_eq"><i>==</i></a> <a href="#abs"><i>abs</i></a> <a href="#abs2"><i>abs2</i></a> <a href="#arg"><i>arg</i></a> <a href="#conjugate"><i>conjugate</i></a> <a href="#image"><i>image</i></a> <a href="#polar"><i>polar</i></a> <a href="#real"><i>real</i></a> <a href="#to_f"><i>to_f</i></a> <a href="#to_i"><i>to_i</i></a> <a href="#to_r"><i>to_r</i></a> <a href="#to_s"><i>to_s</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="500">
<tr>
<td colspan="3" valign="top"><code>require "complex"</code></td>
</tr>
<tr>
<td colspan="3" valign="top"><code></code></td>
</tr>
<tr>
<td valign="top"><code>v1 = Complex(2,3)</code></td>
<td valign="top"></td>
<td valign="top"><code>Complex(2, 3)</code></td>
</tr>
<tr>
<td valign="top"><code>v2 = 2.im</code></td>
<td valign="top"></td>
<td valign="top"><code>Complex(0, 2)</code></td>
</tr>
<tr>
<td valign="top"><code>v1 + v2</code></td>
<td valign="top"></td>
<td valign="top"><code>Complex(2, 5)</code></td>
</tr>
<tr>
<td valign="top"><code>v1 * v2</code></td>
<td valign="top"></td>
<td valign="top"><code>Complex(-6, 4)</code></td>
</tr>
<tr>
<td valign="top"><code>v2**2</code></td>
<td valign="top"></td>
<td valign="top"><code>Complex(-4, 0)</code></td>
</tr>
<tr>
<td valign="top"><code>Math.sin(v1)</code></td>
<td valign="top"></td>
<td valign="top"><code>Complex(9.154499147, -4.16890696)</code></td>
</tr>
<tr>
<td valign="top"><code>v1 < v2</code></td>
<td valign="top"></td>
<td valign="top"><code>false</code></td>
</tr>
<tr>
<td valign="top"><code>v2**2 == -4</code></td>
<td valign="top"></td>
<td valign="top"><code>true</code></td>
</tr>
</table>
<P></P>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="3" bgcolor="990066"><font color="white" size="6">
constants
</font></td></tr></table><table border="2" cellpadding="5">
<tr>
<td valign="top"><tr>
<td><a name="Complex::I"><code>Complex::I</code></a></td>
<td></td>
<td>0 +1<sub>i</sub></td>
</tr>
</td>
</tr>
</table><p></p>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new"><b>new</b></a></font></td><td bgcolor="#ffaaaa">
Complex.new( <i>a</i>, <i>b</i> )
-> <i>aComplex</i>
</td></tr><td></td><td>
<P></P>
Returns a + b<sub>i</sub>.
<P></P>
</td></table>
<P></P>
In addition to the <code>Complex#new</code> constructor, the <code>Complex</code>
library defines the method <a href="ref_c_numeric.html#im"><code>Numeric::im</code></a>, such that
<i>aNumeric</i><code>.im</code> returns 0 + <i>aNumeric</i><sub>i</sub>. Complex
numbers are also constructed using the global method
<code>Complex</code>, which takes one or two arguments. The value it
returns depends on the type of its arguments:
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<tr bgcolor="#ff9999">
<td valign="top"><b>a</b></td>
<td valign="top"><b>b</b></td>
<td valign="top"><b>Result</b></td>
</tr>
<tr>
<td valign="top">Number</td>
<td valign="top">Number</td>
<td valign="top"> a + b<sub>i</sub> </td>
</tr>
<tr>
<td valign="top">Complex</td>
<td valign="top">0</td>
<td valign="top"><i>a</i></td>
</tr>
<tr>
<td valign="top">Complex</td>
<td valign="top">Complex</td>
<td valign="top"><code>Complex( <i>a</i>.real - <i>b</i>.image,
<i>a</i>.image + <i>b</i>.real )</code></td>
</tr>
<tr>
<td valign="top">Number</td>
<td valign="top">Complex</td>
<td valign="top"><code>Complex( <i>a</i> - <i>b</i>.image,
<i>b</i>.real )</code></td>
</tr>
<tr><td colspan="9" bgcolor="#ff9999" height="2"><img src="dot.gif" width="1" height="1"></td></tr></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="Arithmeticoperations"><b>Arithmetic operations</b></a></font></td><td bgcolor="#ffaaaa">
<P></P>
</td></tr><td></td><td>
<P></P>
Performs various arithmetic operations on <i>ref</i>.
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<tr>
<td valign="top"><i>ref</i></td>
<td valign="top">+</td>
<td valign="top"><i>aNumeric</i>
-> <i>aComplex</i></td>
<td valign="top">Addition</td>
</tr>
<tr>
<td valign="top"><i>ref</i></td>
<td valign="top">-</td>
<td valign="top"><i>aNumeric</i>
-> <i>aComplex</i></td>
<td valign="top">Subtraction</td>
</tr>
<tr>
<td valign="top"><i>ref</i></td>
<td valign="top">*</td>
<td valign="top"><i>aNumeric</i>
-> <i>aComplex</i></td>
<td valign="top">Multiplication</td>
</tr>
<tr>
<td valign="top"><i>ref</i></td>
<td valign="top">/</td>
<td valign="top"><i>aNumeric</i>
-> <i>aComplex</i></td>
<td valign="top">Division</td>
</tr>
<tr>
<td valign="top"><i>ref</i></td>
<td valign="top">%</td>
<td valign="top"><i>aNumeric</i>
-> <i>aComplex</i></td>
<td valign="top">Remainder</td>
</tr>
<tr>
<td valign="top"><i>ref</i></td>
<td valign="top">**</td>
<td valign="top"><i>aNumeric</i>
-> <i>aComplex</i></td>
<td valign="top">Exponentiation (real and
complex power)</td>
</tr>
</table>
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_lt_eq_lt"><b><=></b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> <=> <i>other</i> -> -1, 0, +1
</td></tr><td></td><td>
<P></P>
Returns <i>ref</i>.abs <code><=></code> <i>other</i>.abs.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_eq_eq"><b>==</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> == <i>anObject</i> -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
If <i>anObject</i> is a complex number, returns <code>true</code> if
its real and imaginary parts match <i>ref</i>. If <i>anObject</i> is a
simple number, returns <code>true</code> if
<i>ref</i>.<code>real</code> equals <i>anObject</i> and
<i>ref</i>.<code>image</code> is zero. Otherwise, attempts to
coerce <i>anObject</i> to a complex number and compares the result.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="abs"><b>abs</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.abs -> <i>aFloat</i>
</td></tr><td></td><td>
<P></P>
Absolute value.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="abs2"><b>abs2</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.abs2 -> <i>aFloat</i>
</td></tr><td></td><td>
<P></P>
Square of absolute value.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="arg"><b>arg</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.arg -> <i>aFloat</i>
</td></tr><td></td><td>
<P></P>
Argument (angle from (1,0)).
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="conjugate"><b>conjugate</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.conjugate
-> <i>aComplex</i>
</td></tr><td></td><td>
<P></P>
Complex conjugate.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="image"><b>image</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.image -> <i>aNumeric</i>
</td></tr><td></td><td>
<P></P>
The imaginary part of <i>ref</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="polar"><b>polar</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.polar -> <i>anArray</i>
</td></tr><td></td><td>
<P></P>
Returns the two-element array: [<i>c</i>.abs, <i>c</i>.arg].
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="real"><b>real</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.real -> <i>aNumeric</i>
</td></tr><td></td><td>
<P></P>
The real part of <i>ref</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="to_f"><b>to_f</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.to_f -> <i>aComplex</i>
</td></tr><td></td><td>
<P></P>
Returns <code>Complex(real.to_f, image.to_f)</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="to_i"><b>to_i</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.to_i -> <i>aComplex</i>
</td></tr><td></td><td>
<P></P>
Returns <code>Complex(real.to_i, image.to_i)</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="to_r"><b>to_r</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.to_r -> <i>aComplex</i>
</td></tr><td></td><td>
<P></P>
Returns <code>Complex(real.to_r, image.to_r)</code>, converting both
parts of the complex to a rational number.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="to_s"><b>to_s</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.to_s -> <i>aString</i>
</td></tr><td></td><td>
<P></P>
String representation of <i>ref</i>.
<P></P>
</td></table>
<P></P>
In addition, the <code>Math</code> functions <code>sqrt</code>, <code>exp</code>, <code>cos</code>,
<code>sin</code>, <code>tan</code>, <code>log</code>, <code>log10</code>, and <code>atan2</code> are
extended to support a <code>Complex</code> argument.
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class Date</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Object</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#exist2_qm">exist2?</a> <a href="#exist_qm">exist?</a> <a href="#existw_qm">existw?</a> <a href="#gregorian_leap_qm">gregorian_leap?</a> <a href="#julian_leap_qm">julian_leap?</a> <a href="#leap_qm">leap?</a> <a href="#new">new</a> <a href="#new1">new1</a> <a href="#new2">new2</a> <a href="#new3">new3</a> <a href="#neww">neww</a> <a href="#today">today</a> <a href="#Accessors"><i>Accessors</i></a> <a href="#_pl"><i>+</i></a> <a href="#_mi_mi"><i>--</i></a> <a href="#_lt_lt"><i><<</i></a> <a href="#_lt_eq_lt"><i><=></i></a> <a href="#_eq_eq_eq"><i>===</i></a> <a href="#_lt_lt"><i>>></i></a> <a href="#downto"><i>downto</i></a> <a href="#england"><i>england</i></a> <a href="#gregorian"><i>gregorian</i></a> <a href="#italy"><i>italy</i></a> <a href="#jd"><i>jd</i></a> <a href="#julian"><i>julian</i></a> <a href="#leap_qm"><i>leap?</i></a> <a href="#mjd"><i>mjd</i></a> <a href="#newsg"><i>newsg</i></a> <a href="#next"><i>next</i></a> <a href="#ns_qm"><i>ns?</i></a> <a href="#os_qm"><i>os?</i></a> <a href="#sg"><i>sg</i></a> <a href="#step"><i>step</i></a> <a href="#succ"><i>succ</i></a> <a href="#to_s"><i>to_s</i></a> <a href="#upto"><i>upto</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="500">
<tr>
<td colspan="3" valign="top"><code>require 'date'</code></td>
</tr>
<tr>
<td colspan="3" valign="top"><code></code></td>
</tr>
<tr>
<td valign="top"><code>d = Date.new(2000, 3, 31)</code></td>
<td valign="top"></td>
<td valign="top"><code>#<Date: 2451635,2299161></code></td>
</tr>
<tr>
<td valign="top"><code>[d.year, d.yday, d.wday]</code></td>
<td valign="top"></td>
<td valign="top"><code>[2000, 91, 5]</code></td>
</tr>
<tr>
<td valign="top"><code>[d.month, d.mday]</code></td>
<td valign="top"></td>
<td valign="top"><code>[3, 31]</code></td>
</tr>
<tr>
<td valign="top"><code>[d.cwyear, d.cweek, d.cwday]</code></td>
<td valign="top"></td>
<td valign="top"><code>[2000, 13, 5]</code></td>
</tr>
<tr>
<td valign="top"><code>[d.jd, d.mjd]</code></td>
<td valign="top"></td>
<td valign="top"><code>[2451635, 51634.5]</code></td>
</tr>
<tr>
<td valign="top"><code>(d << 1).to_s</code></td>
<td valign="top"></td>
<td valign="top"><code>"2000-02-29"</code></td>
</tr>
<tr>
<td valign="top"><code>d.succ.to_s</code></td>
<td valign="top"></td>
<td valign="top"><code>"2000-04-01"</code></td>
</tr>
<tr>
<td valign="top"><code>(d + 100).to_s</code></td>
<td valign="top"></td>
<td valign="top"><code>"2000-07-09"</code></td>
</tr>
<tr>
<td valign="top"><code>d.leap?</code></td>
<td valign="top"></td>
<td valign="top"><code>true</code></td>
</tr>
<tr>
<td valign="top"><code>Date.new(2000, 3, -10).to_s</code></td>
<td valign="top"></td>
<td valign="top"><code>"2000-03-22"</code></td>
</tr>
<tr>
<td valign="top"><code>d1 = Date.neww(2000, 13, 7)</code></td>
<td valign="top"></td>
<td valign="top"><code>#<Date: 2451637,2299161></code></td>
</tr>
<tr>
<td valign="top"><code>d1.to_s</code></td>
<td valign="top"></td>
<td valign="top"><code>"2000-04-02"</code></td>
</tr>
<tr>
<td valign="top"><code>[d1.cwday, d1.wday]</code></td>
<td valign="top"></td>
<td valign="top"><code>[7, 0]</code></td>
</tr>
</table>
<P></P>
<P></P>
The <code>date</code> library implements class <code>Date</code>, which provides a
comprehensive set of facilities for storing, manipulating, and
converting dates. To document its options, we need to take a brief
historical detour to establish some vocabulary.
<P></P>
Internally a date is stored as a Julian day number, the number of
days since midday, January 1st, 4713 BCE.<em>[In
the code, you may find references to the year -4712. As astronomical
dates include a year zero, 4713 BCE is the same year as
-4712.]</em> The rules for converting a Julian day number to a
calendar date are complicated because the Romans estimated the
length of a year incorrectly. In the Julian calendar (often called
Old Style, or O.S.), every year divisible by 4 is a leap year.
The <code>Date</code> class has options to convert dates using this as an
assumption.
<P></P>
By the sixteenth century, the inaccuracies in this measurement had
become apparent. An edict from Pope Gregory XIII in 1582 created the
New Style (N.S.) or Gregorian calendar, where years divisible by 100 were no
longer leap years unless they were also divisible by 400. This system was
adopted by most Catholic countries immediately, but religious
differences held up a wider adoption. England (and several other
countries) switched in 1752, with some countries following later.
The <code>Date</code> class allows you to determine whether to implement the
cutover in 1582 (the <code>Date::ITALY</code> option), 1752
(<code>Date::ENGLAND</code>), or another date of your choosing.
<P></P>
The <code>Date</code> class also provides conversions to Modified Julian Day
(MJD) numbers.
MJD values count from midnight, November 17, 1858. Because these
values count from midnight, not midday, there is a half-day added to the
conversion factor.
<P></P>
The descriptions that follow use the abbreviations listed
in Table 24.1 on page 445.
<P></P>
<table border="2" width="500" bgcolor="#ffe0e0"><tr><td>
<b>Abbreviations used describing dates</b>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<tr bgcolor="#ff9999">
<td valign="top"><b>Field</b></td>
<td valign="top"><b>Meaning</b></td>
</tr>
<tr>
<td valign="top">cwday</td>
<td valign="top">An ISO 8601 calendar weekday. 1 is Monday, 7 is Sunday.</td>
</tr>
<tr>
<td valign="top">cweek</td>
<td valign="top">An ISO 8601 calendar week. Week 1 is the week containing the
first Thursday (or equivalently the week that contains
January 4th).</td>
</tr>
<tr>
<td valign="top">cwyear</td>
<td valign="top">An ISO 8601 calendar-week-based year. May be different from
<i>year</i>, as it rolls forward only on a Monday.</td>
</tr>
<tr>
<td valign="top">jd</td>
<td valign="top">The Julian day number---the number of days since January
1st, 4713 BCE.</td>
</tr>
<tr>
<td valign="top">mday</td>
<td valign="top">The day of the month (1..31).</td>
</tr>
<tr>
<td valign="top">mjd</td>
<td valign="top">A modified Julian day number.</td>
</tr>
<tr>
<td valign="top">mon</td>
<td valign="top">The month of the year (1..12).</td>
</tr>
<tr>
<td valign="top">sg</td>
<td valign="top">The start of the Gregorian correction: <code>Date::ITALY</code> (the
default) for 1582, <code>Date::ENGLAND</code> for 1752, or
<code>JULIAN</code>, meaning no correction. You may also provide an
arbitrary Julian day number for this parameter, in which case the
correction will start from this date.</td>
</tr>
<tr>
<td valign="top">wday</td>
<td valign="top">The day of the week (0 is Sunday).</td>
</tr>
<tr>
<td valign="top">week</td>
<td valign="top">The week number into a year (1..53).</td>
</tr>
<tr>
<td valign="top">yday</td>
<td valign="top">The day into the year (1..366).</td>
</tr>
<tr>
<td valign="top">year</td>
<td valign="top">A year (1966, 2001, and the like).</td>
</tr>
<tr><td colspan="9" bgcolor="#ff9999" height="2"><img src="dot.gif" width="1" height="1"></td></tr></table>
<P></P>
</td></tr></table>
<P></P>
Class <code>Date</code> exports the constant arrays <code>Date::MONTHNAMES</code>
and <code>Date::DAYNAMES</code>, which can be indexed by <i>mon</i> and
<i>wday</i> values to return the corresponding English names.
<P></P>
The <code>Date</code> class also provides low-level date-conversion methods:
<P></P>
<center>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<tr>
<td valign="top">* <code>civil_to_jd</code></td>
<td valign="top">* <code>jd_to_civil</code></td>
</tr>
<tr>
<td valign="top">* <code>commercial_to_jd</code></td>
<td valign="top">* <code>jd_to_commercial</code></td>
</tr>
<tr>
<td valign="top">* <code>ordinal_to_jd</code></td>
<td valign="top">* <code>jd_to_ordinal</code></td>
</tr>
<tr>
<td valign="top">* <code>jd_to_mjd</code></td>
<td valign="top">* <code>mjd_to_jd</code></td>
</tr>
</table>
<P></P>
</center>
<P></P>
These methods perform limited error checking of their parameters, and are not
documented here. The somewhat confusingly named <code>exist..?</code>
routines perform conversions from different formats into a Julian day
number with error checking. These routines also automatically
normalize their parameters.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">
mixins
</font></td></tr>
<tr><td>Comparable:
</td><td>
<, <=, ==, >=, >, between?</td></tr>
</table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="exist2_qm"><b>exist2?</b></a></font></td><td bgcolor="#ffaaaa">
Date.exist2?(
<i>year</i>, <i>yday</i>, <i>sg</i>=<code>Date::ITALY</code>) -> <i>jd</i>
</td></tr><td></td><td>
<P></P>
Converts a <i>year</i> and <i>yday</i> into a Julian day number,
returning <code>nil</code> on error.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="exist_qm"><b>exist?</b></a></font></td><td bgcolor="#ffaaaa">
Date.exist?( <i>year</i>, <i>mon</i>,
<i>mday</i>, <i>sg</i>=<code>Date::ITALY</code>) -> <i>jd</i>
</td></tr><td></td><td>
<P></P>
Converts a <i>year</i>, <i>mon</i>, and <i>mday</i> into a Julian day
number, or <code>nil</code> if the parameters are invalid.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="existw_qm"><b>existw?</b></a></font></td><td bgcolor="#ffaaaa">
Date.existw?(
<i>cyear</i>, <i>cweek</i>, <i>cwday</i>, <i>sg</i>=<code>Date::ITALY</code>)
-> <i>jd</i>
</td></tr><td></td><td>
Converts a <i>cyear</i>,
<i>cweek</i>, and <i>cwday</i> into a Julian day number.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="gregorian_leap_qm"><b>gregorian_leap?</b></a></font></td><td bgcolor="#ffaaaa">
Date.gregorian_leap?( <i>year</i>
) -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
If <i>year</i> does not end with ``00'', returns <code>true</code> if
<i>year</i> is divisible by 4, otherwise returns <code>true</code>
if <i>year</i> is divisible by 400.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="julian_leap_qm"><b>julian_leap?</b></a></font></td><td bgcolor="#ffaaaa">
Date.julian_leap?( <i>year</i> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if <i>year</i> is divisible by 4.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="leap_qm"><b>leap?</b></a></font></td><td bgcolor="#ffaaaa">
Date.leap?( <i>year</i> ) -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Synonym for <code>Date#gregorian_leap?</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new"><b>new</b></a></font></td><td bgcolor="#ffaaaa">
Date.new( <i>year</i>=-4712, <i>mon</i>=1, <i>mday</i>=1,
<i>sg</i>=<code>Date::ITALY</code>) -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a <code>Date</code> for the given <i>year</i>, <i>mon</i>, and
<i>mday</i>. If <i>mon</i> is negative, it counts back from the end of the
year. If <i>mday</i> is negative, it counts back from the
end of the month.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new1"><b>new1</b></a></font></td><td bgcolor="#ffaaaa">
Date.new1( <i>jd</i>, <i>sg</i>=<code>Date::ITALY</code>)
-> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Creates a <code>Date</code> corresponding to the given Julian day
number.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new2"><b>new2</b></a></font></td><td bgcolor="#ffaaaa">
Date.new2( <i>year</i>=-4712, <i>yday</i>=1,
<i>sg</i>=<code>Date::ITALY</code>) -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a <code>Date</code> for the given <i>year</i> and
<i>yday</i>. If <i>yday</i> is negative, it counts back from the
end of the year.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new3"><b>new3</b></a></font></td><td bgcolor="#ffaaaa">
Date.new3( <i>year</i>=-4712, <i>mon</i>=1, <i>mday</i>=1,
<i>sg</i>=<code>Date::ITALY</code>) -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Synonym for <code>Date#new</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="neww"><b>neww</b></a></font></td><td bgcolor="#ffaaaa">
Date.neww( <i>cyear</i>=1582, <i>cweek</i>=41,
<i>cwday</i>=5, <i>sg</i>=<code>Date::ITALY</code>) -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns
a <code>Date</code> for the given <i>cyear</i>, <i>cweek</i>, and
<i>cwday</i>. If <i>cweek</i> is negative, it counts back from the end
of the year. If <i>cwday</i> is negative, it counts back
from the end of the week.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="today"><b>today</b></a></font></td><td bgcolor="#ffaaaa">
Date.today( <i>sg</i>=<code>Date::ITALY</code>)
-> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a <code>Date</code> for today.
<P></P>
</td></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="Accessors"><b>Accessors</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.year -> <i>year</i><br><i>ref</i>.yday -> <i>yday</i><br><i>ref</i>.mjd -> <i>mjd</i><br><i>ref</i>.mon -> <i>mon</i><br><i>ref</i>.month -> <i>mon</i><br><i>ref</i>.mday -> <i>mday</i><br><i>ref</i>.day -> <i>mday</i><br><i>ref</i>.cwyear -> <i>cwyear</i><br><i>ref</i>.cweek -> <i>cweek</i><br><i>ref</i>.cwday -> <i>cwday</i><br><i>ref</i>.wday -> <i>wday</i>
</td></tr><td></td><td>
<P></P>
Returns the given component of <i>ref</i> as a number.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_pl"><b>+</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> + <i>anInteger</i>
-> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a new <code>Date</code> <i>anInteger</i> days from <i>ref</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_mi_mi"><b>--</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> <code>-</code> <i>anInteger</i> -> <i>aNewDate</i><br><i>ref</i> <code>-</code> <i>anOtherDate</i> -> <i>anInteger</i>
</td></tr><td></td><td>
<P></P>
The first form returns a new <code>Date</code> <i>anInteger</i> days
before <i>ref</i>.
The second form
returns the number of days between <i>ref</i> and <i>anOtherDate</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_lt_lt"><b><<</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> << <i>anInteger</i> -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a new <code>Date</code> formed by subtracting <i>anInteger</i> months to <i>ref</i>,
adjusting the <i>mday</i> value back to the last day of the month if it
otherwise exceeds it.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_lt_eq_lt"><b><=></b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> <=> <i>anOther</i> -> -1, 0, +1
</td></tr><td></td><td>
<P></P>
<i>anOther</i> must be a <code>Numeric</code>, in which case it is
treated as
a Julian day number, or a <code>Date</code>.
Returns -1, 0, +1 if <i>ref</i> is
less than, equal to, or greater than <i>anOther</i>. See module
<code>Comparable</code> on page 406.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_eq_eq_eq"><b>===</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> === <i>anOther</i> -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
<i>anOther</i> must be a <code>Numeric</code>, in which case it is
treated as
a Julian day number, or a <code>Date</code>.
Returns <code>true</code> if the
Julian day number of <i>anOther</i> is the same as <i>ref</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_lt_lt"><b>>></b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i> >> <i>anInteger</i> -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a new <code>Date</code> formed by adding <i>anInteger</i> months to <i>ref</i>,
adjusting the <i>mday</i> value back to the last day of the month if it
otherwise exceeds it.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="downto"><b>downto</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.downto( <i>aDateMin</i> )
{| date | block }
<P></P>
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Invokes block with dates from <i>ref</i> down to <i>aDateMin</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="england"><b>england</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.england -> <i>aDate</i>
</td></tr><td></td><td>
<P></P>
Equivalent to <i>ref</i><code>.newsg(Date::ENGLAND)</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="gregorian"><b>gregorian</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.gregorian
-> <i>aDate</i>
</td></tr><td></td><td>
<P></P>
Equivalent to <i>ref</i><code>.newsg(Date::GREGORIAN)</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="italy"><b>italy</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.italy -> <i>aDate</i>
</td></tr><td></td><td>
<P></P>
Equivalent to <i>ref</i><code>.newsg(Date::ITALY)</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="jd"><b>jd</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.jd -> <i>jd</i>
</td></tr><td></td><td>
<P></P>
Returns the Julian day number for <i>ref</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="julian"><b>julian</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.julian -> <i>aDate</i>
</td></tr><td></td><td>
<P></P>
Equivalent to <i>ref</i><code>.newsg(Date::JULIAN)</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="leap_qm"><b>leap?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.leap? -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if <i>ref</i> falls within a leap year.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="mjd"><b>mjd</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.mjd -> <i>mjd</i>
</td></tr><td></td><td>
<P></P>
Returns the Julian day number of <i>ref</i> converted to a modified Julian
day number.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="newsg"><b>newsg</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.newsg( <i>sg</i>=<code>Date::ITALY</code> )
-> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns a new <code>Date</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="next"><b>next</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.next -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Synonym for <i>ref</i>.succ.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="ns_qm"><b>ns?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.ns? -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if <i>ref</i> falls in the period of New Style dates.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="os_qm"><b>os?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.os? -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if <i>ref</i> falls in the period of Old Style dates.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="sg"><b>sg</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.sg -> <i>anInteger</i>
</td></tr><td></td><td>
<P></P>
Returns the Julian day number of the start of New Style dates for
<i>ref</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="step"><b>step</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.step( <i>aDateLimit</i>, <i>step</i> )
{| date | block }
<P></P>
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Invokes block with dates starting at <i>ref</i>,
incrementing by <i>step</i> days, ending at the first date greater than
<i>aDateLimit</i> (less than for a negative step).
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="succ"><b>succ</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.succ -> <i>aNewDate</i>
</td></tr><td></td><td>
<P></P>
Returns the date of <i>ref</i> plus one day.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="to_s"><b>to_s</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.to_s -> <i>aString</i>
</td></tr><td></td><td>
<P></P>
Returns <code>self</code> as ``year-mon-mday.''
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="upto"><b>upto</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.upto( <i>aDateMax</i> )
{| date | block }
<P></P>
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Invokes block with dates from <i>ref</i> to <i>aDateMax</i>.
<P></P>
</td></table>
<P></P>
<P></P>
<table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">
Library: English</font></td></tr></table><p></p>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require "English"
<P></P>
$OUTPUT_FIELD_SEPARATOR = ' -- '
"waterbuffalo" =~ /buff/
print $LOADED_FEATURES, $POSTMATCH, $PID, "\n"
print $", $', $$, "\n"
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
English.rb -- alo -- 14806 --
English.rb -- alo -- 14806 --
</pre></td></tr></table>
<P></P>
Include the English library file in a Ruby script, and you can
reference the global variables such as <code>$_</code> using less
cryptic names, listed in the following table. <table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<P></P>
<tr><td colspan="9" bgcolor="#ff9999" height="3"><img src="dot.gif" width="1" height="1"></td></tr><tr>
<td valign="top"><code>$*</code></td>
<td valign="top">$ARGV</td>
<td valign="top"><code>$"</code></td>
<td valign="top">$LOADED_FEATURES</td>
</tr>
<tr>
<td valign="top"><code>$?</code></td>
<td valign="top">$CHILD_STATUS</td>
<td valign="top"><code>$&</code></td>
<td valign="top">$MATCH</td>
</tr>
<tr>
<td valign="top"><code>$<</code></td>
<td valign="top">$DEFAULT_INPUT</td>
<td valign="top"><code>$.</code></td>
<td valign="top">$NR</td>
</tr>
<tr>
<td valign="top"><code>$></code></td>
<td valign="top">$DEFAULT_OUTPUT</td>
<td valign="top"><code>$,</code></td>
<td valign="top">$OFS</td>
</tr>
<tr>
<td valign="top"><code>$!</code></td>
<td valign="top">$ERROR_INFO</td>
<td valign="top"><code>$\</code></td>
<td valign="top">$ORS</td>
</tr>
<tr>
<td valign="top"><code>$@</code></td>
<td valign="top">$ERROR_POSITION</td>
<td valign="top"><code>$\</code></td>
<td valign="top">$OUTPUT_RECORD_SEPARATOR</td>
</tr>
<tr>
<td valign="top"><code>$;</code></td>
<td valign="top">$FIELD_SEPARATOR</td>
<td valign="top"><code>$,</code></td>
<td valign="top">$OUTPUT_FIELD_SEPARATOR</td>
</tr>
<tr>
<td valign="top"><code>$;</code></td>
<td valign="top">$FS</td>
<td valign="top"><code>$$</code></td>
<td valign="top">$PID</td>
</tr>
<tr>
<td valign="top"><code>$=</code></td>
<td valign="top">$IGNORECASE</td>
<td valign="top"><code>$'</code></td>
<td valign="top">$POSTMATCH</td>
</tr>
<tr>
<td valign="top"><code>$.</code></td>
<td valign="top">$INPUT_LINE_NUMBER</td>
<td valign="top"><code>$`</code></td>
<td valign="top">$PREMATCH</td>
</tr>
<tr>
<td valign="top"><code>$/</code></td>
<td valign="top">$INPUT_RECORD_SEPARATOR</td>
<td valign="top"><code>$$</code></td>
<td valign="top">$PROCESS_ID</td>
</tr>
<tr>
<td valign="top"><code>$~</code></td>
<td valign="top">$LAST_MATCH_INFO</td>
<td valign="top"><code>$0</code></td>
<td valign="top">$PROGRAM_NAME</td>
</tr>
<tr>
<td valign="top"><code>$+</code></td>
<td valign="top">$LAST_PAREN_MATCH</td>
<td valign="top"><code>$/</code></td>
<td valign="top">$RS</td>
</tr>
<tr>
<td valign="top"><code>$_</code></td>
<td valign="top">$LAST_READ_LINE</td>
</tr>
<tr><td colspan="9" bgcolor="#ff9999" height="2"><img src="dot.gif" width="1" height="1"></td></tr></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">module Find</font></td></tr></table><p></p><H3>Index:</H3><a href="#find">find</a> <a href="#prune">prune</a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require "find"
Find.find("/etc/passwd", "/var/spool/lp1", ".") do |f|
Find.prune if f == "."
puts f
end
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
/etc/passwd
/var/spool/lp1
/var/spool/lp1/status
/var/spool/lp1/lock
/var/spool/lp1/.seq
</pre></td></tr></table>
<P></P>
The <code>Find</code> module supports the top-down traversal of a set of
file paths.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="find"><b>find</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.find( <i>[</i><i>aName</i><i>]<sup>*</sup></i> ) {| aFileName | block }
<P></P>
</td></tr><td></td><td>
<P></P>
Calls the associated block with the name of every file and
directory listed as arguments, then recursively on their
subdirectories, and so on.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="prune"><b>prune</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.prune
</td></tr><td></td><td>
<P></P>
Skips the current file or directory, restarting the
loop with the next entry. If the current file is a directory,
that directory will not be recursively entered.
Meaningful only within the block associated with
<code>Find#find</code>.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class File</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">IO</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#cmp">cmp</a> <a href="#compare">compare</a> <a href="#copy">copy</a> <a href="#cp">cp</a> <a href="#install">install</a> <a href="#makedirs">makedirs</a> <a href="#mkpath">mkpath</a> <a href="#move">move</a> <a href="#mv">mv</a> <a href="#rm_f">rm_f</a> <a href="#safe_unlink">safe_unlink</a> <a href="#syscopy">syscopy</a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="500">
<tr>
<td colspan="3" valign="top"><code>require 'ftools'</code></td>
</tr>
<tr>
<td colspan="3" valign="top"><code></code></td>
</tr>
<tr>
<td valign="top"><code>File.copy 'testfile', 'testfile1'</code></td>
<td valign="top"></td>
<td valign="top"><code>true</code></td>
</tr>
<tr>
<td valign="top"><code>File.compare 'testfile', 'testfile1'</code></td>
<td valign="top"></td>
<td valign="top"><code>true</code></td>
</tr>
</table>
<P></P>
<P></P>
The <code>FTools</code> library adds several methods to the built-in
<code>File</code> class. These methods are particularly useful to programs
that move and copy files, such as installers.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="cmp"><b>cmp</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.cmp( <i>name1</i>, <i>name2</i>,
<i>verbose</i>=<code>false</code> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Synonym for <a href="ref_c_file.html#compare"><code>File::compare</code></a>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="compare"><b>compare</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.compare( <i>name1</i>, <i>name2</i>,
<i>verbose</i>=<code>false</code> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> only if the contents of files <i>name1</i>
and <i>name2</i> are identical.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="copy"><b>copy</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.copy( <i>fromName</i>, <i>toName</i>,
<i>verbose</i>=<code>false</code> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Equivalent to calling <a href="ref_c_file.html#syscopy"><code>File::syscopy</code></a>, but logs the attempt to
<code>$stderr</code> if <i>verbose</i> is not <code>false</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="cp"><b>cp</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.cp( <i>fromName</i>, <i>toName</i>,
<i>verbose</i>=<code>false</code> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Synonym for <a href="ref_c_file.html#copy"><code>File::copy</code></a>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="install"><b>install</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.install( <i>fromName</i>, <i>toName</i>,
<i>aMode</i>=<code>nil</code>, <i>verbose</i>=<code>false</code> )
</td></tr><td></td><td>
<P></P>
Copies file <i>fromName</i> to file <i>toName</i> using
<a href="ref_c_file.html#syscopy"><code>File::syscopy</code></a>, unless <i>toName</i> already exists and has the
same content as <i>fromName</i>. Sets the mode of the resulting file
to <i>aMode</i> unless <i>aMode</i> is <code>nil</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="makedirs"><b>makedirs</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.makedirs(
<i>[</i><i>dirName</i><i>]<sup>*</sup></i> <i>[</i>, <i>aBoolean</i><i>]</i> )
</td></tr><td></td><td>
<P></P>
Creates the given directories, logging each attempt to
<code>$stderr</code> if the last parameter is
<code>true</code>. Creates any missing parent directories as
required.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="mkpath"><b>mkpath</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.mkpath(
<i>[</i><i>dirName</i><i>]<sup>*</sup></i> <i>[</i>, <i>aBoolean</i><i>]</i> )
</td></tr><td></td><td>
<P></P>
Synonym for <a href="ref_c_file.html#makedirs"><code>File::makedirs</code></a>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="move"><b>move</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.move( <i>fromName</i>, <i>toName</i>,
<i>verbose</i>=<code>false</code> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Effectively renames <i>fromName</i> to <i>toName</i>, logging to
<code>$stderr</code> if <i>verbose</i> is not <code>false</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="mv"><b>mv</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.mv( <i>fromName</i>, <i>toName</i>,
<i>verbose</i>=<code>false</code> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Synonym for <a href="ref_c_file.html#move"><code>File::move</code></a>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="rm_f"><b>rm_f</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.rm_f(
<i>[</i><i>fileName</i><i>]<sup>*</sup></i> <i>[</i>, <i>aBoolean</i><i>]</i> )
-> <i>anInteger</i>
</td></tr><td></td><td>
<P></P>
Synonym for <a href="ref_c_file.html#safe_unlink"><code>File::safe_unlink</code></a> (the name refers
to the Unix <code>rm -f</code> command).
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="safe_unlink"><b>safe_unlink</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.safe_unlink(
<i>[</i><i>fileName</i><i>]<sup>*</sup></i> <i>[</i>, <i>aBoolean</i><i>]</i> )
-> <i>anInteger</i> or <code>nil</code>
</td></tr><td></td><td>
<P></P>
Unlinks (deletes) the given files, logging to <code>$stderr</code> if
the last parameter is <code>true</code>. The method attempts to make all files
writable before unlinking them, so no errors will occur deleting
read-only files. Returns the number of files deleted, or <code>nil</code>
on error.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="syscopy"><b>syscopy</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.syscopy( <i>fromName</i>, <i>toName</i> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Efficiently copies the file named <i>fromName</i> to
<i>toName</i>. If <i>toName</i> names a directory, the destination
will be a file in that directory with the same basename as
<i>fromName</i>. After the copy, the file mode of <i>toName</i>
will be the same as that of <i>fromName</i>. Returns <code>true</code>
on success.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class GetoptLong</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Object</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#new">new</a> <a href="#each"><i>each</i></a> <a href="#error_qm"><i>error?</i></a> <a href="#error_message"><i>error_message</i></a> <a href="#get"><i>get</i></a> <a href="#get_option"><i>get_option</i></a> <a href="#ordering"><i>ordering</i></a> <a href="#ordering_eq"><i>ordering=</i></a> <a href="#quiet"><i>quiet</i></a> <a href="#quiet_eq"><i>quiet=</i></a> <a href="#quiet_qm"><i>quiet?</i></a> <a href="#set_options"><i>set_options</i></a> <a href="#terminate"><i>terminate</i></a> <a href="#terminated_qm"><i>terminated?</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
# Call using "ruby example.rb --size 10k -v -q a.txt b.doc"
<P></P>
require 'getoptlong'
<P></P>
# specify the options we accept and initialize
# the option parser
<P></P>
opts = GetoptLong.new(
[ "--size", "-s", GetoptLong::REQUIRED_ARGUMENT ],
[ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
[ "--query", "-q", GetoptLong::NO_ARGUMENT ],
[ "--check", "--valid", "-c", GetoptLong::NO_ARGUMENT ]
)
<P></P>
# process the parsed options
<P></P>
opts.each do |opt, arg|
puts "Option: #{opt}, arg #{arg.inspect}"
end
<P></P>
puts "Remaining args: #{ARGV.join(', ')}"
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
Option: --size, arg "10k"
Option: --verbose, arg ""
Option: --query, arg ""
Remaining args: a.txt, b.doc
</pre></td></tr></table>
<P></P>
Class <code>GetoptLong</code> supports GNU-style command-line option parsing.
Options may be a minus sign (`-') followed by a single character, or
two minus signs (`--') followed by a name (a long option). Long
options may be abbreviated to their shortest unambiguous lengths.
<P></P>
A single internal option may have multiple external representations.
For example, the option to control verbose output could be any of
<code>-v</code>, <code>--verbose</code>, or <code>--details</code>. Some options may
also take an associated value.
<P></P>
Each internal option is passed to <code>GetoptLong</code> as an array,
containing strings representing the option's external forms and a
flag. The flag (<code>NO_ARGUMENT</code>, <code>REQUIRED_ARGUMENT</code>, or
<code>OPTIONAL_ARGUMENT</code>) specifies how <code>GetoptLong</code> is to
associate an argument with the option.
<P></P>
If the environment variable
<code>POSIXLY_CORRECT</code> is set, all options
must precede nonoptions on the command line. Otherwise, the default
behavior of <code>GetoptLong</code> is to reorganize the command line to put
the options at the front. This behavior may be changed by setting
<code>GetoptLong#ordering=</code> to one of the constants
<code>PERMUTE</code>, <code>REQUIRE_ORDER</code>, or <code>RETURN_IN_ORDER</code>.
<code>POSIXLY_CORRECT</code> may not be overridden.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="3" bgcolor="990066"><font color="white" size="6">
constants
</font></td></tr></table><table border="2" cellpadding="5">
<tr bgcolor="#ff9999">
<td valign="top"><em><b>Per-option constants</b></em></td>
</tr>
<P></P>
<tr>
<td><a name="NO_ARGUMENT"><code>NO_ARGUMENT</code></a></td>
<td></td>
<td>Flags an option that takes no argument.</td>
</tr>
<P></P>
<tr>
<td><a name="OPTIONAL_ARGUMENT"><code>OPTIONAL_ARGUMENT</code></a></td>
<td></td>
<td>A nonoption following this option
will be used as this option's argument.</td>
</tr>
<P></P>
<tr>
<td><a name="REQUIRED_ARGUMENT"><code>REQUIRED_ARGUMENT</code></a></td>
<td></td>
<td>This option must be followed by an
argument.</td>
</tr>
<P></P>
<tr><td colspan="9" bgcolor="#ff9999" height="3"><img src="dot.gif" width="1" height="1"></td></tr><tr>
<td valign="top"><em><b>Overall constants</b></em></td>
</tr>
<P></P>
<tr>
<td><a name="PERMUTE"><code>PERMUTE</code></a></td>
<td></td>
<td>Options and their arguments will be shuffled
to the front of the command line.</td>
</tr>
<P></P>
<tr>
<td><a name="REQUIRE_ORDER"><code>REQUIRE_ORDER</code></a></td>
<td></td>
<td>Options and their arguments must
appear at the start of the command line. The first nonoption
terminates option processing.</td>
</tr>
<P></P>
<tr>
<td><a name="RETURN_IN_ORDER"><code>RETURN_IN_ORDER</code></a></td>
<td></td>
<td>Return options in the order in
which they occur on the command line.</td>
</tr>
<P></P>
<tr><td colspan="9" bgcolor="#ff9999" height="2"><img src="dot.gif" width="1" height="1"></td></tr></table><p></p>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new"><b>new</b></a></font></td><td bgcolor="#ffaaaa">
GetoptLong.new( <i>[</i><i>options</i><i>]<sup>*</sup></i> ) -> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Returns a new option parser. Any <i>options</i> are passed to
<i>ref</i>.<code>set_options</code>.
<P></P>
</td></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="each"><b>each</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.each {| anOption, anArgument | block }
<P></P>
</td></tr><td></td><td>
<P></P>
Loops calling <code>GetoptLong#get</code>, passing the returned option
and argument to the associated block. The loop ends when <code>get</code>
returns <code>nil</code> for <i>anOption</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="error_qm"><b>error?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.error?
-> <i>anException</i>
</td></tr><td></td><td>
<P></P>
Returns an <code>Exception</code> object documenting any error that has
occurred, or <code>nil</code> if there has not been an error.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="error_message"><b>error_message</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.error_message
-> <i>aString</i>
</td></tr><td></td><td>
<P></P>
Returns the text of the last error message.
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="get"><b>get</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.get -> [ <i>anOption</i>,
<i>anArgument</i> ]
</td></tr><td></td><td>
<P></P>
Returns the next option, along with any associated argument. If
there is no argument, <code>nil</code> is returned for
<i>anArgument</i>. If there are no remaining unprocessed options,
or if there is an error in option processing and <code>quiet</code>
has been set, <code>nil</code> is returned for
<i>anOption</i>. Otherwise,
if there is an error, a message is written to <code>$stderr</code> and
an exception (a subclass of <code>StandardError</code>) is raised.
<P></P>
The option string returned is the first option that was given in
the corresponding array passed to <code>set_options</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="get_option"><b>get_option</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.get_option -> [ <i>anOption</i>,
<i>anArgument</i> ]
</td></tr><td></td><td>
<P></P>
Synonym for <code>GetoptLong#get</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="ordering"><b>ordering</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.ordering -> <i>aFixnum</i>
</td></tr><td></td><td>
<P></P>
Returns the current ordering.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="ordering_eq"><b>ordering=</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.ordering = <i>aFixnum</i>
</td></tr><td></td><td>
<P></P>
Sets the ordering to one of <code>PERMUTE</code>, <code>REQUIRE_ORDER</code>,
or <code>RETURN_IN_ORDER</code>. Quietly ignored if the environment
variable <code>POSIXLY_CORRECT</code> is set. Ordering may not be
changed once option processing has been started.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="quiet"><b>quiet</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.quiet -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns the current value of the <code>quiet</code> attribute.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="quiet_eq"><b>quiet=</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.quiet = <code>true</code> or <code>false</code></td></tr><td></td><td>
<P></P>
Sets the current value of the <code>quiet</code> attribute. If
<code>false</code>, any errors encountered are reported to
<code>$stderr</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="quiet_qm"><b>quiet?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.quiet? -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Synonym for <code>GetoptLong#quiet</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="set_options"><b>set_options</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.set_options(
<i>[</i><i>anOptArray</i><i>]<sup>*</sup></i> ) -> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Each parameter is an array specifying a single internal option.
The array contains one or more strings specifying the external
form(s) of the option, and one of the flags <code>NO_ARGUMENT</code>,
<code>OPTIONAL_ARGUMENT</code>, or <code>REQUIRED_ARGUMENT</code>. See the
sample code on page 452 for examples of use.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="terminate"><b>terminate</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.terminate -> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Terminates option processing. Any remaining arguments are
written back to <code>ARGV</code>. This may be called from within a
<code>GetoptLong#each</code> or on its own. For example, calling the
following program using ``<code>ruby example.rb --size 10k -v
-term -q a.txt b.doc</code>'' will leave the <code>-q</code> and filenames
in <code>ARGV</code>.
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require 'getoptlong'
<P></P>
opts = GetoptLong.new(
[ "--size", "-s", GetoptLong::REQUIRED_ARGUMENT ],
[ "--verbose", "-v", GetoptLong::NO_ARGUMENT ],
[ "--term", "-t", GetoptLong::NO_ARGUMENT ],
[ "--query", "-q", GetoptLong::NO_ARGUMENT ],
[ "--check", "--valid", "-c", GetoptLong::NO_ARGUMENT ]
)
<P></P>
opts.each do |opt, arg|
puts "Option: #{opt}, arg #{arg.inspect}"
opts.terminate if (opt == '--term')
end
<P></P>
puts "Remaining args: #{ARGV.join(', ')}"
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
Option: --size, arg "10k"
Option: --verbose, arg ""
Option: --term, arg ""
Remaining args: -q, a.txt, b.doc
</pre></td></tr></table>
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="terminated_qm"><b>terminated?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.terminated?
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if option processing has been terminated.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">module mkmf</font></td></tr></table><p></p><H3>Index:</H3><a href="#create_makefile"><i>create_makefile</i></a> <a href="#dir_config"><i>dir_config</i></a> <a href="#find_library"><i>find_library</i></a> <a href="#have_func"><i>have_func</i></a> <a href="#have_header"><i>have_header</i></a> <a href="#have_library"><i>have_library</i></a> <p></p><hr>
<P></P>
The <code>mkmf</code> library is used by Ruby extension modules to help
create <code>Makefiles</code>. When writing an extension, you create a
program named ``<code>extconf.rb</code>'', which may be as simple as:
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require 'mkmf'
create_makefile("Test")
</pre></td></tr></table>
<P></P>
When run, this script will produce a <code>Makefile</code> suited to the
target platform. <code>mkmf</code> contains several methods you can use
to find libraries and include files and to set compiler flags.
<P></P>
For more information on creating extension modules, see Chapter
17, which begins on page 171.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="3" bgcolor="990066"><font color="white" size="6">
constants
</font></td></tr></table><table border="2" cellpadding="5">
<tr>
<td valign="top"><tr>
<td><a name="PLATFORM"><code>PLATFORM</code></a></td>
<td>varies</td>
<td>A constant string that describes the
platform on which Ruby is running, such as ``mswin32'' or
``i686-linux.''</td>
</tr>
<P></P>
<tr>
<td><a name="$CFLAGS"><code>$CFLAGS</code></a></td>
<td></td>
<td>Global variable for compiler flags.</td>
</tr>
<P></P>
<tr>
<td><a name="$LDFLAGS"><code>$LDFLAGS</code></a></td>
<td></td>
<td>Global variable for linker flags.</td>
</tr>
</td>
</tr>
</table><p></p>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="create_makefile"><b>create_makefile</b></a></font></td><td bgcolor="#ffaaaa">
create_makefile( <i>target</i> )
</td></tr><td></td><td>
<P></P>
Creates a <code>Makefile</code> for an extension named <em>target</em>.
If this method is not called, no <code>Makefile</code> is created.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="dir_config"><b>dir_config</b></a></font></td><td bgcolor="#ffaaaa">
dir_config( <i>name</i> )
</td></tr><td></td><td>
<P></P>
Looks for directory configuration options for <em>name</em> given
as arguments to this program or to the original build of Ruby.
These arguments may be one of:
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<tr>
<td valign="top"><code>--with-</code><em>name</em><code>-dir</code>=<em>directory</em></td>
</tr>
<tr>
<td valign="top"><code>--with-</code><em>name</em><code>-include</code>=<em>directory</em></td>
</tr>
<tr>
<td valign="top"><code>--with-</code><em>name</em><code>-lib</code>=<em>directory</em></td>
</tr>
</table>
<P></P>
The given directories will be added to the appropriate search
paths (include or link) in the <code>Makefile</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="find_library"><b>find_library</b></a></font></td><td bgcolor="#ffaaaa">
find_library( <i>name</i>,
<i>function</i>, <i>[</i><i>path</i><i>]<sup>+</sup></i> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Same as <code>have_library</code>, but will also search in the given
directory paths.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="have_func"><b>have_func</b></a></font></td><td bgcolor="#ffaaaa">
have_func( <i>function</i> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
If the named
function exists in the standard compile environment,
adds the directive -DHAVE_<em>FUNCTION</em>
to the compile command in the <code>Makefile</code> and returns <code>true</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="have_header"><b>have_header</b></a></font></td><td bgcolor="#ffaaaa">
have_header( <i>header</i> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
If the given header file can be found in the
standard search path, adds the directive -DHAVE_<em>HEADER</em>
to the compile command in the <code>Makefile</code> and returns <code>true</code>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="have_library"><b>have_library</b></a></font></td><td bgcolor="#ffaaaa">
have_library( <i>library</i>,
<i>function</i> ) -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
If the given function exists in the named library, which must exist in
the standard search path or in a directory added with
<code>dir_config</code>, adds the library to the link command
in the <code>Makefile</code> and returns <code>true</code>.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">module ParseDate</font></td></tr></table><p></p><H3>Index:</H3><a href="#parsedate">parsedate</a> <p></p><hr>
<P></P>
The <code>ParseDate</code> module defines a single method,
<code>ParseDate#parsedate</code>, which converts a date and/or time string
into its constituents. It uses heuristics that handle a wide
variety of date and time formats, including a subset of ISO 8601,
Unix <code>ctime</code>, and most common written variants. The following table shows
some examples.
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3">
<tr bgcolor="#ff9999">
<td colspan="2" valign="top"><b>StringGuess?</b></td>
<td valign="top"><b>yy</b></td>
<td valign="top"><b>mm</b></td>
<td valign="top"><b>dd</b></td>
<td valign="top"><b>hh</b></td>
<td valign="top"><b>min</b></td>
<td valign="top"><b>sec</b></td>
<td valign="top"><b>zone</b></td>
<td valign="top"><b>wd</b></td>
</tr>
<tr>
<td valign="top">1999-09-05 23:55:21+0900</td>
<td valign="top">F</td>
<td valign="top">1999</td>
<td valign="top">9</td>
<td valign="top">5</td>
<td valign="top">23</td>
<td valign="top">55</td>
<td valign="top">21</td>
<td valign="top">+0900</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">1983-12-25</td>
<td valign="top">F</td>
<td valign="top">1983</td>
<td valign="top">12</td>
<td valign="top">25</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">1965-11-10 T13:45</td>
<td valign="top">F</td>
<td valign="top">1965</td>
<td valign="top">11</td>
<td valign="top">10</td>
<td valign="top">13</td>
<td valign="top">45</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">10/9/75 1:30pm</td>
<td valign="top">F</td>
<td valign="top">75</td>
<td valign="top">10</td>
<td valign="top">9</td>
<td valign="top">13</td>
<td valign="top">30</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">10/9/75 1:30pm</td>
<td valign="top">T</td>
<td valign="top">1975</td>
<td valign="top">10</td>
<td valign="top">9</td>
<td valign="top">13</td>
<td valign="top">30</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">Mon Feb 28 17:15:49 CST 2000</td>
<td valign="top">F</td>
<td valign="top">2000</td>
<td valign="top">2</td>
<td valign="top">28</td>
<td valign="top">17</td>
<td valign="top">15</td>
<td valign="top">49</td>
<td valign="top">CST</td>
<td valign="top">1</td>
</tr>
<tr>
<td valign="top">Tue, 02-Mar-99 11:20:32 GMT</td>
<td valign="top">F</td>
<td valign="top">99</td>
<td valign="top">3</td>
<td valign="top">2</td>
<td valign="top">11</td>
<td valign="top">20</td>
<td valign="top">32</td>
<td valign="top">GMT</td>
<td valign="top">2</td>
</tr>
<tr>
<td valign="top">Tue, 02-Mar-99 11:20:32 GMT</td>
<td valign="top">T</td>
<td valign="top">1999</td>
<td valign="top">3</td>
<td valign="top">2</td>
<td valign="top">11</td>
<td valign="top">20</td>
<td valign="top">32</td>
<td valign="top">GMT</td>
<td valign="top">2</td>
</tr>
<tr>
<td valign="top">12-January-1990, 04:00 WET</td>
<td valign="top">F</td>
<td valign="top">1990</td>
<td valign="top">1</td>
<td valign="top">12</td>
<td valign="top">4</td>
<td valign="top">0</td>
<td valign="top">--</td>
<td valign="top">WET</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">4/3/99</td>
<td valign="top">F</td>
<td valign="top">99</td>
<td valign="top">4</td>
<td valign="top">3</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">4/3/99</td>
<td valign="top">T</td>
<td valign="top">1999</td>
<td valign="top">4</td>
<td valign="top">3</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">10th February, 1976</td>
<td valign="top">F</td>
<td valign="top">1976</td>
<td valign="top">2</td>
<td valign="top">10</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">March 1st, 84</td>
<td valign="top">T</td>
<td valign="top">1984</td>
<td valign="top">3</td>
<td valign="top">1</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
</tr>
<tr>
<td valign="top">Friday</td>
<td valign="top">F</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">--</td>
<td valign="top">5</td>
</tr>
<tr><td colspan="9" bgcolor="#ff9999" height="2"><img src="dot.gif" width="1" height="1"></td></tr></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="parsedate"><b>parsedate</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.parsedate( <i>aString</i>, <i>guessYear</i>=<code>false</code> )<br>-> [ <i>year</i>, <i>mon</i>, <i>mday</i>,
<i>hour</i>, <i>min</i>, <i>sec</i>, <i>zone</i>, <i>wday</i>
]
</td></tr><td></td><td>
<P></P>
Parses a string containing a date and/or a time, returning an
array of <code>Fixnum</code> objects containing the various components.
<code>nil</code> is returned for fields that cannot be parsed from
<i>aString</i>. If the result contains a year that is less than
100 and <i>guessYear</i> is true, <code>parsedate</code> will return
a year value equal to <i>year</i> plus 2000 if <i>year</i> is less
than 69, <i>year</i> plus 1900 otherwise.
<P></P>
</td></table>
<P></P>
<P></P>
<table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">
Library: profile</font></td></tr></table><p></p>
<P></P>
The <code>profile</code> library prints to <code>$stderr</code> a summary
of the number of calls to, and the time spent in, each method in a
Ruby program. The output is sorted by the total time spent in each
method. Profiling can be enabled from the command line using the
<code>-r</code><code>profile</code> option, or from within a source program by
requiring the <code>profile</code> module.
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require 'profile'
def ackerman(m, n)
if m == 0 then n+1
elsif n == 0 and m > 0 then ackerman(m-1, 1)
else ackerman(m-1, ackerman(m, n-1))
end
end
ackerman(3,3)
</pre></td></tr></table>
<P></P>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="500"><tr><td><pre>
time seconds seconds calls ms/call ms/call name
70.77 2.30 2.30 2432 0.95 41.42 Object#ackerman
14.46 2.77 0.47 3676 0.13 0.13 Fixnum#==
9.54 3.08 0.31 2431 0.13 0.13 Fixnum#-
4.92 3.24 0.16 1188 0.13 0.13 Fixnum#+
0.31 3.25 0.01 57 0.18 0.18 Fixnum#>
0.00 3.25 0.00 1 0.00 0.00 Module#method_added
0.00 3.25 0.00 1 0.00 3250.00 #toplevel
</pre></td></tr></table>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class PStore</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Object</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#new">new</a> <a href="#_ob_cb"><i>[ ]</i></a> <a href="#_ob_cb_eq"><i>[ ]=</i></a> <a href="#abort"><i>abort</i></a> <a href="#commit"><i>commit</i></a> <a href="#path"><i>path</i></a> <a href="#root_qm"><i>root?</i></a> <a href="#roots"><i>roots</i></a> <a href="#transaction"><i>transaction</i></a> <p></p><hr>
<P></P>
The <code>PStore</code> class provides transactional, file-based
persistent storage of Ruby objects. The following example stores two
hierarchies in a PStore. The first, identified by the key
``<code>names</code>'', is an array of Strings. The second, identified by
``<code>tree</code>'', is a simple binary tree.
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require "pstore"
<P></P>
class T
def initialize(val, left=nil, right=nil)
@val, @left, @right = val, left, right
end
def to_a
[ @val, @left.to_a, @right.to_a ]
end
end
<P></P>
store = PStore.new("/tmp/store")
store.transaction do
store['names'] = [ 'Douglas', 'Barenberg', 'Meyer' ]
store['tree'] = T.new('top',
T.new('A', T.new('B')),
T.new('C', T.new('D', nil, T.new('E'))))
end
<P></P>
# now read it back in
<P></P>
store.transaction do
puts "Roots: #{store.roots.join(', ')}"
puts store['names'].join(', ')
puts store['tree'].to_a.inspect
end
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
Roots: names, tree
Douglas, Barenberg, Meyer
["top", ["A", ["B", [], []], []], ["C", ["D", [], ["E", [], []]], []]]
</pre></td></tr></table>
<P></P>
Each <code>PStore</code> can store several
object hierarchies. Each hierarchy has a root, identified by a key
(often a string). At the start of a <code>PStore</code> transaction, these
hierarchies are read from a disk file and made available to the Ruby
program. At the end of the transaction, the hierarchies are written
back to the file. Any changes made to objects in these hierarchies
are therefore saved on disk, to be read at the start of the next
transaction that uses that file.
<P></P>
In normal use, a <code>PStore</code> object is created and then is used one or
more times to control a transaction. Within the body of the
transaction, any object hierarchies that had previously been saved
are made available, and any changes to object hierarchies, and any
new hierarchies, are written back to the file at the end.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new"><b>new</b></a></font></td><td bgcolor="#ffaaaa">
PStore.new( <i>aFilename</i> )
-> <i>aPStore</i>
</td></tr><td></td><td>
<P></P>
Returns a new <code>PStore</code> object associated with the given
file. If the file exists, its contents must have been previously
written by <code>PStore</code>.
<P></P>
</td></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_ob_cb"><b>[ ]</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>[ <i>anObject</i> ] -> <i>anOtherObject</i>
</td></tr><td></td><td>
<P></P>
Root Access---Returns the root of an object hierarchy identified
by <i>anObject</i>. An exception is raised if <i>anObject</i> does
not identify a root.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="_ob_cb_eq"><b>[ ]=</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>[ <i>anObject</i> ] =
<i>anOtherObject</i>
-> <i>anOtherObject</i>
</td></tr><td></td><td>
<P></P>
Root Creation---Sets <i>anOtherObject</i> as the base of the object
hierarchy to be identified using <i>anObject</i>.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="abort"><b>abort</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.abort
</td></tr><td></td><td>
<P></P>
Terminates this transaction, losing any changes made to the
object hierarchies.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="commit"><b>commit</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.commit
</td></tr><td></td><td>
<P></P>
Terminates the current transaction, saving the object hierarchies
into the store's file.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="path"><b>path</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.path -> <i>aString</i>
</td></tr><td></td><td>
<P></P>
Returns the name of the file associated with this store.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="root_qm"><b>root?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.root?( <i>anObject</i> )
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if <i>anObject</i> is the key of a root in
this store.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="roots"><b>roots</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.roots -> <i>anArray</i>
</td></tr><td></td><td>
<P></P>
Returns an array containing the keys of the root objects
available in this store.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="transaction"><b>transaction</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.transaction {| <i>ref</i> | block }
<P></P>
-> <i>anObject</i>
</td></tr><td></td><td>
<P></P>
If the file associated with <i>ref</i> exists, reads in the object
hierarchies from it. It then executes the associated block, passing
in <i>ref</i>. The block may use this parameter to access the roots
of the hierarchies and hence access the persistent objects. If
the block calls <code>PStore#abort</code>, or if it raises an exception,
no data is saved back to the associated file. Otherwise, if it
invokes <code>PStore#commit</code>, or if it terminates normally, the
object hierarchies are written back to the file. The value
returned is the value returned by the block.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class Tempfile</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">[IO]</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#new">new</a> <a href="#close"><i>close</i></a> <a href="#open"><i>open</i></a> <a href="#path"><i>path</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="500">
<tr>
<td colspan="3" valign="top"><code>require "tempfile"</code></td>
</tr>
<tr>
<td colspan="3" valign="top"><code></code></td>
</tr>
<tr>
<td colspan="3" valign="top"><code>tf = Tempfile.new("afile")</code></td>
</tr>
<tr>
<td valign="top"><code>tf.path</code></td>
<td valign="top"></td>
<td valign="top"><code>"/tmp/afile14822.0"</code></td>
</tr>
<tr>
<td valign="top"><code>tf.puts("Cosi Fan Tutte")</code></td>
<td valign="top"></td>
<td valign="top"><code>nil</code></td>
</tr>
<tr>
<td valign="top"><code>tf.close</code></td>
<td valign="top"></td>
<td valign="top"><code>nil</code></td>
</tr>
<tr>
<td valign="top"><code>tf.open</code></td>
<td valign="top"></td>
<td valign="top"><code>#<File:0x4016e3c0></code></td>
</tr>
<tr>
<td valign="top"><code>tf.gets</code></td>
<td valign="top"></td>
<td valign="top"><code>"Cosi Fan Tutte\n"</code></td>
</tr>
<tr>
<td valign="top"><code>tf.close(true)</code></td>
<td valign="top"></td>
<td valign="top"><code>#<File:0x4016e3c0>\n0x40187c30</code></td>
</tr>
</table>
<P></P>
<P></P>
Class <code>Tempfile</code> creates managed temporary files. Although they
behave the same as any other <code>IO</code> objects, temporary files are
automatically deleted when the Ruby program terminates. Once a
<code>Tempfile</code> object has been created, the underlying file may be
opened and closed a number of times in succession.
<P></P>
<code>Tempfile</code> does not directly inherit from <code>IO</code>. Instead, it
delegates calls to a <code>File</code> object. From the programmer's
perspective, apart from the unusual <code>new</code>, <code>open,</code> and
<code>close</code> semantics, a <code>Tempfile</code> object behaves as if it
were an <code>IO</code> object.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new"><b>new</b></a></font></td><td bgcolor="#ffaaaa">
Tempfile.new( <i>basename</i>,
<i>tmpdir</i>=<see below> )
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Constructs a temporary file in the given directory. The file
name is built by concatenating <i>basename</i>, the current
process id and (as an extension) a unique sequence number. If
the <i>tmpdir</i> parameter is not supplied, it defaults to the
value of one of the environment variables <code>TMPDIR</code>, <code>TMP</code>,
or <code>TEMP</code>, or to the directory <code>/tmp</code>.
<P></P>
The file is then opened using mode ``w+'', which allows reading
and writing and deletes any existing content (see Table
22.5 on page 331).
<P></P>
</td></table>
<P></P>
<tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="open"><b>open</b></a></font></td><td bgcolor="#ffaaaa">
Tempfile.open( <i>basename</i>,
<i>tmpdir</i> )
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Synonym for <code>Tempfile#new</code>.
<P></P>
</td>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="close"><b>close</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.close( <i>final</i>=<code>false</code> )
</td></tr><td></td><td>
<P></P>
Closes <i>ref</i>. If <i>final</i> is <code>true</code>, deletes the underlying
real file. If <i>final</i> is <code>false</code>, <i>ref</i> may be
subsequently reopened. In all cases, the underlying file is
deleted when the program terminates.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="open"><b>open</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.open
</td></tr><td></td><td>
<P></P>
Reopens <i>ref</i> using mode ``r+'', which allows reading and
writing but does not delete existing content.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="path"><b>path</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.path -> <i>aString</i>
</td></tr><td></td><td>
<P></P>
Returns the full path of the underlying file.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class Mutex</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Object</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#lock"><i>lock</i></a> <a href="#locked_qm"><i>locked?</i></a> <a href="#synchronize"><i>synchronize</i></a> <a href="#try_lock"><i>try_lock</i></a> <a href="#unlock"><i>unlock</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require 'thread'
sema4 = Mutex.new
<P></P>
a = Thread.new {
sema4.synchronize {
# access shared resource
}
}
<P></P>
b = Thread.new {
sema4.synchronize {
# access shared resource
}
}
</pre></td></tr></table>
<P></P>
<code>Mutex</code> implements a simple semaphore that can be used to
coordinate access to shared data from multiple concurrent threads.
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="lock"><b>lock</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.lock
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Attempts to grab the lock and waits if it isn't available.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="locked_qm"><b>locked?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.locked?
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>true</code> if this lock is currently held by some
thread.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="synchronize"><b>synchronize</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.synchronize { block }
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Obtains a lock (using <code>Mutex#lock</code>), runs the block,
and releases the lock when the block completes.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="try_lock"><b>try_lock</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.try_lock -> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Attempts to obtain the lock and returns
immediately. Returns <code>true</code> if the lock was granted.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="unlock"><b>unlock</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.unlock
-> <i>ref</i> or <code>nil</code>
</td></tr><td></td><td>
<P></P>
Releases the lock. Returns <code>nil</code> if <i>ref</i> wasn't locked.
<P></P>
</td></table>
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class ConditionVariable</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Object</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#broadcast"><i>broadcast</i></a> <a href="#signal"><i>signal</i></a> <a href="#wait"><i>wait</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require 'thread'
mutex = Mutex.new
resource = ConditionVariable.new
<P></P>
a = Thread.new {
mutex.synchronize {
# Thread 'a' now needs the resource
resource.wait(mutex)
# 'a' can now have the resource
}
}
<P></P>
b = Thread.new {
mutex.synchronize {
# Thread 'b' has finished using the resource
resource.signal
}
}
</pre></td></tr></table>
<P></P>
<code>ConditionVariable</code> objects augment class <code>Mutex</code>. Using
condition variables, it is possible to suspend while in the middle
of a critical section until a resource becomes available (see the discussion
on page 119).
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="broadcast"><b>broadcast</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.broadcast
</td></tr><td></td><td>
<P></P>
Wakes up all threads waiting for this lock.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="signal"><b>signal</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.signal
</td></tr><td></td><td>
<P></P>
Wakes up the first thread in line waiting for this lock.
<P></P>
</td><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="wait"><b>wait</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.wait( <i>aMutex</i> )
-> <i>aMutex</i>
</td></tr><td></td><td>
<P></P>
Releases the lock held in <i>aMutex</i> and waits; reacquires
the lock on wakeup.
<P></P>
</td></table>
<P></P>
<P></P>
<table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">
Library: timeout</font></td></tr></table><p></p>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require "timeout"
<P></P>
for snooze in 1..2
puts "About to sleep for #{snooze}"
timeout(1.5) do
sleep(snooze)
end
puts "That was refreshing"
end
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
About to sleep for 1
That was refreshing
About to sleep for 2
/tc/usr/lib/ruby/1.6/timeout.rb:37: execution expired (TimeoutError)
from prog.rb:5:in `timeout'
from prog.rb:5
from prog.rb:3:in `each'
from prog.rb:3
</pre></td></tr></table>
<P></P>
The <code>timeout</code> method takes a single parameter, representing
a timeout period in seconds, and a block. The block is executed, and
a timer is run concurrently. If the block terminates before the
timeout, <code>timeout</code> returns <code>true</code>. Otherwise, a
<code>TimeoutError</code> exception is raised.
<P></P>
<P></P>
<table><tr><td height="20"><img src="dot.gif" width="1" height="20"></td></tr></table><table border="0" width="100%" bgcolor="660066" cellpadding="10"><tr><td valign="center"><font color="white" size="7">class WeakRef</font></td><td><table border="0"><tr><td><font color="white">
Parent:
</font></td><td><font color="white">Delegator</font></td></tr><tr><td><font color="white">
Version:
</font></td><td><font color="white">
1.6
</font></td></tr></table></td></tr></table><p></p><H3>Index:</H3><a href="#new">new</a> <a href="#weakref_alive_qm"><i>weakref_alive?</i></a> <p></p><hr>
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
require "weakref"
<P></P>
ref = "fol de rol"
puts "Initial object is #{ref}"
ref = WeakRef.new(ref)
puts "Weak reference is #{ref}"
ObjectSpace.garbage_collect
puts "But then it is #{ref}"
</pre></td></tr></table>
<em>produces:</em>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
Initial object is fol de rol
Weak reference is fol de rol
n finals=>1
0x40188a7c
n finals=>0
prog.rb:8: Illegal Reference - probably recycled (WeakRef::RefError)
</pre></td></tr></table>
<P></P>
In Ruby, objects are not eligible for garbage collection if there
are still references to them. Normally, this is a Good Thing---it
would be disconcerting to have an object simply evaporate while you
were using it. However, sometimes you may need more flexibility. For
example, you might want to implement an in-memory cache of commonly
used file contents. As you read more files, the cache grows. At some
point, you may run low on memory. The garbage collector will be
invoked, but the objects in the cache are all referenced by the
cache data structures, and so will not be deleted.
<P></P>
A weak reference behaves
exactly as any normal object reference with one important
exception---the referenced object may be garbage collected, even
while references to it exist. In the cache example, if the cached
files were accessed using weak references, once memory runs low they
will be garbage collected, freeing memory for the rest of the
application.
<P></P>
Weak references introduce a slight complexity. As the object
referenced can be deleted by garbage collection at any time, code
that accesses these objects must take care to ensure that the
references are valid. Two techniques can be used. First, the code
can reference the objects normally. Any attempt to reference an
object that has been garbage collected will raise a
<code>WeakRef::RefError</code> exception.
<P></P>
An alternative approach is to use the <code>WeakRef#weakref_alive?</code>
method to check that a reference is valid before using it. Garbage
collection must be disabled during the test and subsequent reference
to the object. In a single-threaded program, you could use something
like:
<P></P>
<table bgcolor="#fff0f0" cellspacing="0" border="0" cellpadding="3" width="400"><tr><td><pre>
ref = WeakRef.new(someObject)
#
# .. some time later
#
<P></P>
gcWasDisabled = GC.disable
if ref.weakref_alive?
# do stuff with 'ref'
end
GC.enable unless gcWasDisabled
</pre></td></tr></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">class methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="new"><b>new</b></a></font></td><td bgcolor="#ffaaaa">
WeakRef.new( <i>anObject</i> )
-> <i>ref</i>
</td></tr><td></td><td>
<P></P>
Creates and returns a weak reference to <i>anObject</i>. All
future references to <i>anObject</i> should be made using <i>ref</i>.
<P></P>
</td></table>
<P></P>
<table border="0" width="100%" cellpadding="10"><tr><td valign="center" colspan="2" bgcolor="990066"><font color="white" size="6">instance methods
</font></td></tr><tr><td valign="center" bgcolor="#ff9999"><font size="4"><a name="weakref_alive_qm"><b>weakref_alive?</b></a></font></td><td bgcolor="#ffaaaa">
<i>ref</i>.weakref_alive?
-> <code>true</code> or <code>false</code>
</td></tr><td></td><td>
<P></P>
Returns <code>false</code> if the object referenced by <i>ref</i> has
been garbage collected.
<P></P>
</td></table>
<P></P>
<P></P>
<p></p><hr><table bgcolor="#a03030" cellpadding="10" border="0" cellspacing="0"><tr><td width="33%" align="left"><a class="subheader" href="builtins.html">Previous <</a></td><td width="33%" align="center" valign="middle"><a class="subheader" href="index.html">Contents ^</a><br></td><td width="33%" align="right"><a class="subheader" href="lib_patterns.html">Next ></a><br></td></tr></table><p></p><font size="-1">Extracted from the book "Programming Ruby -
The Pragmatic Programmer's Guide"</font><br><font size="-3">
Copyright
©
2000 Addison Wesley Longman, Inc. Released under the terms of the
<a href="http://www.opencontent.org/openpub/">Open Publication License</a> V1.0.
<br>
This reference is available for
<a href="http://www.pragmaticprogrammer.com/ruby/downloads/book.html">download</a>.
</font></body></html>
|