rio 0.3.2 → 0.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (248) hide show
  1. data/ChangeLog +49 -0
  2. data/VERSION +1 -1
  3. data/doc/ANNOUNCE +19 -2
  4. data/doc/RELEASE_NOTES +17 -0
  5. data/ex/colx.rb +3 -1
  6. data/ex/passwd_report.rb +12 -0
  7. data/lib/rio.rb +8 -9
  8. data/lib/rio/argv.rb +0 -4
  9. data/lib/rio/base.rb +3 -1
  10. data/lib/rio/doc/INTRO.rb +74 -1
  11. data/lib/rio/ext/csv.rb +34 -5
  12. data/lib/rio/factory.rb +2 -2
  13. data/lib/rio/if.rb +3 -0
  14. data/lib/rio/if/csv.rb +76 -0
  15. data/lib/rio/if/dir.rb +14 -6
  16. data/lib/rio/if/fileordir.rb +6 -0
  17. data/lib/rio/if/grande.rb +28 -0
  18. data/lib/rio/if/internal.rb +75 -2
  19. data/lib/rio/if/methods.rb +4 -3
  20. data/lib/rio/if/string.rb +46 -0
  21. data/lib/rio/if/temp.rb +46 -0
  22. data/lib/rio/matchcolumns.rb +266 -0
  23. data/lib/rio/rangemath.rb +44 -0
  24. data/lib/rio/scheme/temp.rb +4 -1
  25. data/lib/rio/version.rb +1 -1
  26. data/test/tc/all.rb +4 -1
  27. data/test/tc/copy-from.rb +1 -1
  28. data/test/tc/csv2.rb +135 -0
  29. data/test/tc/csv_columns.rb +37 -0
  30. data/test/tc/csvutil.rb +56 -0
  31. data/test/tc/ext.rb +1 -1
  32. data/test/tc/methods.rb +1 -1
  33. data/test/tc/tempfile.rb +17 -0
  34. metadata +11 -228
  35. data/doc/rdoc/classes/Kernel.html +0 -181
  36. data/doc/rdoc/classes/Kernel.src/M000182.html +0 -18
  37. data/doc/rdoc/classes/RIO.html +0 -543
  38. data/doc/rdoc/classes/RIO.src/M000001.html +0 -18
  39. data/doc/rdoc/classes/RIO.src/M000002.html +0 -18
  40. data/doc/rdoc/classes/RIO.src/M000003.html +0 -18
  41. data/doc/rdoc/classes/RIO/Doc.html +0 -138
  42. data/doc/rdoc/classes/RIO/Doc/HOWTO.html +0 -1035
  43. data/doc/rdoc/classes/RIO/Doc/INTRO.html +0 -1335
  44. data/doc/rdoc/classes/RIO/Doc/MISC.html +0 -443
  45. data/doc/rdoc/classes/RIO/Doc/SYNOPSIS.html +0 -355
  46. data/doc/rdoc/classes/RIO/Rio.html +0 -6358
  47. data/doc/rdoc/classes/RIO/Rio.src/M000004.html +0 -18
  48. data/doc/rdoc/classes/RIO/Rio.src/M000005.html +0 -20
  49. data/doc/rdoc/classes/RIO/Rio.src/M000006.html +0 -27
  50. data/doc/rdoc/classes/RIO/Rio.src/M000007.html +0 -27
  51. data/doc/rdoc/classes/RIO/Rio.src/M000008.html +0 -16
  52. data/doc/rdoc/classes/RIO/Rio.src/M000009.html +0 -18
  53. data/doc/rdoc/classes/RIO/Rio.src/M000010.html +0 -20
  54. data/doc/rdoc/classes/RIO/Rio.src/M000011.html +0 -16
  55. data/doc/rdoc/classes/RIO/Rio.src/M000012.html +0 -16
  56. data/doc/rdoc/classes/RIO/Rio.src/M000013.html +0 -16
  57. data/doc/rdoc/classes/RIO/Rio.src/M000014.html +0 -16
  58. data/doc/rdoc/classes/RIO/Rio.src/M000015.html +0 -16
  59. data/doc/rdoc/classes/RIO/Rio.src/M000016.html +0 -16
  60. data/doc/rdoc/classes/RIO/Rio.src/M000017.html +0 -16
  61. data/doc/rdoc/classes/RIO/Rio.src/M000018.html +0 -16
  62. data/doc/rdoc/classes/RIO/Rio.src/M000019.html +0 -16
  63. data/doc/rdoc/classes/RIO/Rio.src/M000020.html +0 -16
  64. data/doc/rdoc/classes/RIO/Rio.src/M000021.html +0 -16
  65. data/doc/rdoc/classes/RIO/Rio.src/M000022.html +0 -16
  66. data/doc/rdoc/classes/RIO/Rio.src/M000023.html +0 -16
  67. data/doc/rdoc/classes/RIO/Rio.src/M000024.html +0 -16
  68. data/doc/rdoc/classes/RIO/Rio.src/M000025.html +0 -16
  69. data/doc/rdoc/classes/RIO/Rio.src/M000026.html +0 -16
  70. data/doc/rdoc/classes/RIO/Rio.src/M000027.html +0 -16
  71. data/doc/rdoc/classes/RIO/Rio.src/M000028.html +0 -16
  72. data/doc/rdoc/classes/RIO/Rio.src/M000029.html +0 -16
  73. data/doc/rdoc/classes/RIO/Rio.src/M000030.html +0 -16
  74. data/doc/rdoc/classes/RIO/Rio.src/M000031.html +0 -16
  75. data/doc/rdoc/classes/RIO/Rio.src/M000032.html +0 -16
  76. data/doc/rdoc/classes/RIO/Rio.src/M000033.html +0 -16
  77. data/doc/rdoc/classes/RIO/Rio.src/M000034.html +0 -16
  78. data/doc/rdoc/classes/RIO/Rio.src/M000035.html +0 -16
  79. data/doc/rdoc/classes/RIO/Rio.src/M000036.html +0 -16
  80. data/doc/rdoc/classes/RIO/Rio.src/M000037.html +0 -16
  81. data/doc/rdoc/classes/RIO/Rio.src/M000038.html +0 -16
  82. data/doc/rdoc/classes/RIO/Rio.src/M000039.html +0 -16
  83. data/doc/rdoc/classes/RIO/Rio.src/M000040.html +0 -16
  84. data/doc/rdoc/classes/RIO/Rio.src/M000041.html +0 -16
  85. data/doc/rdoc/classes/RIO/Rio.src/M000042.html +0 -16
  86. data/doc/rdoc/classes/RIO/Rio.src/M000043.html +0 -16
  87. data/doc/rdoc/classes/RIO/Rio.src/M000044.html +0 -16
  88. data/doc/rdoc/classes/RIO/Rio.src/M000045.html +0 -16
  89. data/doc/rdoc/classes/RIO/Rio.src/M000046.html +0 -16
  90. data/doc/rdoc/classes/RIO/Rio.src/M000047.html +0 -16
  91. data/doc/rdoc/classes/RIO/Rio.src/M000048.html +0 -16
  92. data/doc/rdoc/classes/RIO/Rio.src/M000049.html +0 -16
  93. data/doc/rdoc/classes/RIO/Rio.src/M000050.html +0 -16
  94. data/doc/rdoc/classes/RIO/Rio.src/M000051.html +0 -16
  95. data/doc/rdoc/classes/RIO/Rio.src/M000052.html +0 -16
  96. data/doc/rdoc/classes/RIO/Rio.src/M000053.html +0 -16
  97. data/doc/rdoc/classes/RIO/Rio.src/M000054.html +0 -16
  98. data/doc/rdoc/classes/RIO/Rio.src/M000055.html +0 -16
  99. data/doc/rdoc/classes/RIO/Rio.src/M000056.html +0 -16
  100. data/doc/rdoc/classes/RIO/Rio.src/M000057.html +0 -16
  101. data/doc/rdoc/classes/RIO/Rio.src/M000058.html +0 -16
  102. data/doc/rdoc/classes/RIO/Rio.src/M000059.html +0 -16
  103. data/doc/rdoc/classes/RIO/Rio.src/M000060.html +0 -16
  104. data/doc/rdoc/classes/RIO/Rio.src/M000061.html +0 -16
  105. data/doc/rdoc/classes/RIO/Rio.src/M000062.html +0 -16
  106. data/doc/rdoc/classes/RIO/Rio.src/M000063.html +0 -16
  107. data/doc/rdoc/classes/RIO/Rio.src/M000064.html +0 -16
  108. data/doc/rdoc/classes/RIO/Rio.src/M000065.html +0 -16
  109. data/doc/rdoc/classes/RIO/Rio.src/M000066.html +0 -16
  110. data/doc/rdoc/classes/RIO/Rio.src/M000067.html +0 -16
  111. data/doc/rdoc/classes/RIO/Rio.src/M000068.html +0 -16
  112. data/doc/rdoc/classes/RIO/Rio.src/M000069.html +0 -16
  113. data/doc/rdoc/classes/RIO/Rio.src/M000070.html +0 -16
  114. data/doc/rdoc/classes/RIO/Rio.src/M000071.html +0 -16
  115. data/doc/rdoc/classes/RIO/Rio.src/M000072.html +0 -16
  116. data/doc/rdoc/classes/RIO/Rio.src/M000073.html +0 -16
  117. data/doc/rdoc/classes/RIO/Rio.src/M000074.html +0 -16
  118. data/doc/rdoc/classes/RIO/Rio.src/M000075.html +0 -16
  119. data/doc/rdoc/classes/RIO/Rio.src/M000076.html +0 -16
  120. data/doc/rdoc/classes/RIO/Rio.src/M000077.html +0 -16
  121. data/doc/rdoc/classes/RIO/Rio.src/M000078.html +0 -16
  122. data/doc/rdoc/classes/RIO/Rio.src/M000079.html +0 -16
  123. data/doc/rdoc/classes/RIO/Rio.src/M000080.html +0 -16
  124. data/doc/rdoc/classes/RIO/Rio.src/M000081.html +0 -16
  125. data/doc/rdoc/classes/RIO/Rio.src/M000082.html +0 -16
  126. data/doc/rdoc/classes/RIO/Rio.src/M000083.html +0 -16
  127. data/doc/rdoc/classes/RIO/Rio.src/M000084.html +0 -16
  128. data/doc/rdoc/classes/RIO/Rio.src/M000085.html +0 -16
  129. data/doc/rdoc/classes/RIO/Rio.src/M000086.html +0 -16
  130. data/doc/rdoc/classes/RIO/Rio.src/M000087.html +0 -16
  131. data/doc/rdoc/classes/RIO/Rio.src/M000088.html +0 -16
  132. data/doc/rdoc/classes/RIO/Rio.src/M000089.html +0 -16
  133. data/doc/rdoc/classes/RIO/Rio.src/M000090.html +0 -16
  134. data/doc/rdoc/classes/RIO/Rio.src/M000091.html +0 -16
  135. data/doc/rdoc/classes/RIO/Rio.src/M000092.html +0 -16
  136. data/doc/rdoc/classes/RIO/Rio.src/M000093.html +0 -16
  137. data/doc/rdoc/classes/RIO/Rio.src/M000094.html +0 -16
  138. data/doc/rdoc/classes/RIO/Rio.src/M000095.html +0 -16
  139. data/doc/rdoc/classes/RIO/Rio.src/M000096.html +0 -16
  140. data/doc/rdoc/classes/RIO/Rio.src/M000097.html +0 -16
  141. data/doc/rdoc/classes/RIO/Rio.src/M000098.html +0 -16
  142. data/doc/rdoc/classes/RIO/Rio.src/M000099.html +0 -16
  143. data/doc/rdoc/classes/RIO/Rio.src/M000100.html +0 -16
  144. data/doc/rdoc/classes/RIO/Rio.src/M000101.html +0 -16
  145. data/doc/rdoc/classes/RIO/Rio.src/M000102.html +0 -16
  146. data/doc/rdoc/classes/RIO/Rio.src/M000103.html +0 -16
  147. data/doc/rdoc/classes/RIO/Rio.src/M000104.html +0 -16
  148. data/doc/rdoc/classes/RIO/Rio.src/M000105.html +0 -16
  149. data/doc/rdoc/classes/RIO/Rio.src/M000106.html +0 -16
  150. data/doc/rdoc/classes/RIO/Rio.src/M000107.html +0 -16
  151. data/doc/rdoc/classes/RIO/Rio.src/M000108.html +0 -16
  152. data/doc/rdoc/classes/RIO/Rio.src/M000109.html +0 -16
  153. data/doc/rdoc/classes/RIO/Rio.src/M000110.html +0 -16
  154. data/doc/rdoc/classes/RIO/Rio.src/M000111.html +0 -16
  155. data/doc/rdoc/classes/RIO/Rio.src/M000112.html +0 -16
  156. data/doc/rdoc/classes/RIO/Rio.src/M000113.html +0 -16
  157. data/doc/rdoc/classes/RIO/Rio.src/M000114.html +0 -16
  158. data/doc/rdoc/classes/RIO/Rio.src/M000115.html +0 -16
  159. data/doc/rdoc/classes/RIO/Rio.src/M000116.html +0 -16
  160. data/doc/rdoc/classes/RIO/Rio.src/M000117.html +0 -16
  161. data/doc/rdoc/classes/RIO/Rio.src/M000118.html +0 -16
  162. data/doc/rdoc/classes/RIO/Rio.src/M000119.html +0 -16
  163. data/doc/rdoc/classes/RIO/Rio.src/M000120.html +0 -16
  164. data/doc/rdoc/classes/RIO/Rio.src/M000121.html +0 -16
  165. data/doc/rdoc/classes/RIO/Rio.src/M000122.html +0 -16
  166. data/doc/rdoc/classes/RIO/Rio.src/M000123.html +0 -16
  167. data/doc/rdoc/classes/RIO/Rio.src/M000124.html +0 -16
  168. data/doc/rdoc/classes/RIO/Rio.src/M000125.html +0 -16
  169. data/doc/rdoc/classes/RIO/Rio.src/M000126.html +0 -16
  170. data/doc/rdoc/classes/RIO/Rio.src/M000127.html +0 -16
  171. data/doc/rdoc/classes/RIO/Rio.src/M000128.html +0 -16
  172. data/doc/rdoc/classes/RIO/Rio.src/M000129.html +0 -16
  173. data/doc/rdoc/classes/RIO/Rio.src/M000130.html +0 -16
  174. data/doc/rdoc/classes/RIO/Rio.src/M000131.html +0 -16
  175. data/doc/rdoc/classes/RIO/Rio.src/M000132.html +0 -16
  176. data/doc/rdoc/classes/RIO/Rio.src/M000133.html +0 -16
  177. data/doc/rdoc/classes/RIO/Rio.src/M000134.html +0 -16
  178. data/doc/rdoc/classes/RIO/Rio.src/M000135.html +0 -16
  179. data/doc/rdoc/classes/RIO/Rio.src/M000136.html +0 -16
  180. data/doc/rdoc/classes/RIO/Rio.src/M000137.html +0 -16
  181. data/doc/rdoc/classes/RIO/Rio.src/M000138.html +0 -16
  182. data/doc/rdoc/classes/RIO/Rio.src/M000139.html +0 -16
  183. data/doc/rdoc/classes/RIO/Rio.src/M000140.html +0 -16
  184. data/doc/rdoc/classes/RIO/Rio.src/M000141.html +0 -16
  185. data/doc/rdoc/classes/RIO/Rio.src/M000142.html +0 -16
  186. data/doc/rdoc/classes/RIO/Rio.src/M000143.html +0 -16
  187. data/doc/rdoc/classes/RIO/Rio.src/M000144.html +0 -16
  188. data/doc/rdoc/classes/RIO/Rio.src/M000145.html +0 -16
  189. data/doc/rdoc/classes/RIO/Rio.src/M000146.html +0 -16
  190. data/doc/rdoc/classes/RIO/Rio.src/M000147.html +0 -16
  191. data/doc/rdoc/classes/RIO/Rio.src/M000148.html +0 -16
  192. data/doc/rdoc/classes/RIO/Rio.src/M000149.html +0 -16
  193. data/doc/rdoc/classes/RIO/Rio.src/M000150.html +0 -16
  194. data/doc/rdoc/classes/RIO/Rio.src/M000151.html +0 -16
  195. data/doc/rdoc/classes/RIO/Rio.src/M000152.html +0 -16
  196. data/doc/rdoc/classes/RIO/Rio.src/M000153.html +0 -16
  197. data/doc/rdoc/classes/RIO/Rio.src/M000154.html +0 -16
  198. data/doc/rdoc/classes/RIO/Rio.src/M000155.html +0 -16
  199. data/doc/rdoc/classes/RIO/Rio.src/M000156.html +0 -16
  200. data/doc/rdoc/classes/RIO/Rio.src/M000157.html +0 -16
  201. data/doc/rdoc/classes/RIO/Rio.src/M000158.html +0 -16
  202. data/doc/rdoc/classes/RIO/Rio.src/M000159.html +0 -16
  203. data/doc/rdoc/classes/RIO/Rio.src/M000160.html +0 -16
  204. data/doc/rdoc/classes/RIO/Rio.src/M000161.html +0 -16
  205. data/doc/rdoc/classes/RIO/Rio.src/M000162.html +0 -16
  206. data/doc/rdoc/classes/RIO/Rio.src/M000163.html +0 -16
  207. data/doc/rdoc/classes/RIO/Rio.src/M000164.html +0 -16
  208. data/doc/rdoc/classes/RIO/Rio.src/M000165.html +0 -16
  209. data/doc/rdoc/classes/RIO/Rio.src/M000166.html +0 -16
  210. data/doc/rdoc/classes/RIO/Rio.src/M000167.html +0 -16
  211. data/doc/rdoc/classes/RIO/Rio.src/M000168.html +0 -16
  212. data/doc/rdoc/classes/RIO/Rio.src/M000169.html +0 -16
  213. data/doc/rdoc/classes/RIO/Rio.src/M000170.html +0 -16
  214. data/doc/rdoc/classes/RIO/Rio.src/M000171.html +0 -16
  215. data/doc/rdoc/classes/RIO/Rio.src/M000172.html +0 -16
  216. data/doc/rdoc/classes/RIO/Rio.src/M000173.html +0 -16
  217. data/doc/rdoc/classes/RIO/Rio.src/M000174.html +0 -16
  218. data/doc/rdoc/classes/RIO/Rio.src/M000175.html +0 -16
  219. data/doc/rdoc/classes/RIO/Rio.src/M000176.html +0 -16
  220. data/doc/rdoc/classes/RIO/Rio.src/M000177.html +0 -16
  221. data/doc/rdoc/classes/RIO/Rio.src/M000178.html +0 -16
  222. data/doc/rdoc/classes/RIO/Rio.src/M000179.html +0 -16
  223. data/doc/rdoc/classes/RIO/Rio.src/M000180.html +0 -16
  224. data/doc/rdoc/classes/RIO/Rio.src/M000181.html +0 -16
  225. data/doc/rdoc/created.rid +0 -1
  226. data/doc/rdoc/files/README.html +0 -215
  227. data/doc/rdoc/files/lib/rio/constructor_rb.html +0 -142
  228. data/doc/rdoc/files/lib/rio/doc/HOWTO_rb.html +0 -135
  229. data/doc/rdoc/files/lib/rio/doc/INTRO_rb.html +0 -135
  230. data/doc/rdoc/files/lib/rio/doc/MISC_rb.html +0 -135
  231. data/doc/rdoc/files/lib/rio/doc/SYNOPSIS_rb.html +0 -135
  232. data/doc/rdoc/files/lib/rio/if/basic_rb.html +0 -135
  233. data/doc/rdoc/files/lib/rio/if/dir_rb.html +0 -135
  234. data/doc/rdoc/files/lib/rio/if/file_rb.html +0 -135
  235. data/doc/rdoc/files/lib/rio/if/fileordir_rb.html +0 -135
  236. data/doc/rdoc/files/lib/rio/if/grande_rb.html +0 -135
  237. data/doc/rdoc/files/lib/rio/if/internal_rb.html +0 -135
  238. data/doc/rdoc/files/lib/rio/if/methods_rb.html +0 -135
  239. data/doc/rdoc/files/lib/rio/if/path_rb.html +0 -135
  240. data/doc/rdoc/files/lib/rio/if/stream_rb.html +0 -135
  241. data/doc/rdoc/files/lib/rio/if/test_rb.html +0 -135
  242. data/doc/rdoc/files/lib/rio/kernel_rb.html +0 -142
  243. data/doc/rdoc/files/lib/rio_rb.html +0 -153
  244. data/doc/rdoc/fr_class_index.html +0 -34
  245. data/doc/rdoc/fr_file_index.html +0 -44
  246. data/doc/rdoc/fr_method_index.html +0 -209
  247. data/doc/rdoc/index.html +0 -24
  248. data/doc/rdoc/rdoc-style.css +0 -384
@@ -1,1335 +0,0 @@
1
- <?xml version="1.0" encoding="iso-8859-1"?>
2
- <!DOCTYPE html
3
- PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
4
- "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
5
-
6
- <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
7
- <head>
8
- <title>Module: RIO::Doc::INTRO</title>
9
- <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
10
- <meta http-equiv="Content-Script-Type" content="text/javascript" />
11
- <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
12
- <script type="text/javascript">
13
- // <![CDATA[
14
-
15
- function popupCode( url ) {
16
- window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
17
- }
18
-
19
- function toggleCode( id ) {
20
- if ( document.getElementById )
21
- elem = document.getElementById( id );
22
- else if ( document.all )
23
- elem = eval( "document.all." + id );
24
- else
25
- return false;
26
-
27
- elemStyle = elem.style;
28
-
29
- if ( elemStyle.display != "block" ) {
30
- elemStyle.display = "block"
31
- } else {
32
- elemStyle.display = "none"
33
- }
34
-
35
- return true;
36
- }
37
-
38
- // Make codeblocks hidden by default
39
- document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
40
-
41
- // ]]>
42
- </script>
43
-
44
- </head>
45
- <body>
46
-
47
-
48
-
49
- <div id="classHeader">
50
- <table class="header-table">
51
- <tr class="top-aligned-row">
52
- <td class="class-mod"><strong>Module</strong></td>
53
- <td class="class-name-in-header">RIO::Doc::INTRO</td>
54
- <td rowspan="2" class="class-header-space-col"></td>
55
- <td rowspan="2">
56
- <a class="in-url" href="../../../files/lib/rio/doc/INTRO_rb.html">
57
- lib/rio/doc/INTRO.rb
58
- </a>
59
- &nbsp;&nbsp;
60
- </td>
61
- </tr>
62
-
63
- </table>
64
- </div>
65
- <!-- banner header -->
66
-
67
- <div id="bodyContent">
68
-
69
-
70
-
71
- <div id="contextContent">
72
-
73
- <div id="description">
74
- <h1><a href="../Rio.html">Rio</a> - Ruby I/O Comfort Class</h1>
75
- <p>
76
- <a href="../Rio.html">Rio</a> is a convenience class wrapping much of the
77
- functionality of IO, File, Dir, Pathname, FileUtils, Tempfile, StringIO,
78
- and OpenURI and uses Zlib, and CSV to extend that functionality using a
79
- simple consistent interface. Most of the instance methods of IO, File and
80
- Dir are simply forwarded to the appropriate handle to provide identical
81
- functionality. <a href="../Rio.html">Rio</a> also provides a
82
- &quot;grande&quot; interface that allows many application level IO tasks to
83
- be accomplished in line or two of code.
84
- </p>
85
- <p>
86
- <a href="../Rio.html">Rio</a> functionality can be broadly broken into
87
- three categories
88
- </p>
89
- <ul>
90
- <li>path manipulation
91
-
92
- </li>
93
- <li>file system access
94
-
95
- </li>
96
- <li>stream manipulation
97
-
98
- </li>
99
- </ul>
100
- <p>
101
- Which methods are available to a given <a href="../Rio.html">Rio</a>,
102
- depends on the underlying object.
103
- </p>
104
- <p>
105
- A <a href="../Rio.html">Rio</a> generally does not need to be opened or
106
- have its mode specified. Most of <a href="../Rio.html">Rio</a>&#8217;s
107
- methods simply configure it. When an actual IO operation is specified, <a
108
- href="../Rio.html">Rio</a> determines how to open it based on the object it
109
- is opening, the operation it is performing, and the options specified.
110
- </p>
111
- <p>
112
- <a href="../Rio.html">Rio</a> configuration methods return the <a
113
- href="../Rio.html">Rio</a> for easy chaining and regard the presence of a
114
- block as an implied <tt>each</tt>.
115
- </p>
116
- <h2>Using a <a href="../Rio.html">Rio</a></h2>
117
- <p>
118
- Using a <a href="../Rio.html">Rio</a> can be described as having 3 steps:
119
- </p>
120
- <ul>
121
- <li>Creating a <a href="../Rio.html">Rio</a> (using the constructor or as the
122
- result of one of the path manipulation methods)
123
-
124
- </li>
125
- <li>Configuring a <a href="../Rio.html">Rio</a>
126
-
127
- </li>
128
- <li><a href="../Rio.html">Rio</a> I/O
129
-
130
- </li>
131
- </ul>
132
- <h3>Creating a <a href="../Rio.html">Rio</a></h3>
133
- <p>
134
- <a href="../Rio.html">Rio</a> extends <a
135
- href="../../Kernel.html">Kernel</a> with one function <tt>rio</tt>, its
136
- constructor. This function is overloaded to create any type of <a
137
- href="../Rio.html">Rio</a>. <tt>rio</tt> looks at the class and sometimes
138
- the value of its first argument to create an internal representation of the
139
- resource specified, additional arguments are used as needed by the resource
140
- type. The rio constructor does not initiate any io, it does not check for a
141
- resources existance or type. It neither knows nor cares what can be done
142
- with this <a href="../Rio.html">Rio</a>. Using methods like +respond_to?+
143
- are meaningless at best and usually misleading.
144
- </p>
145
- <p>
146
- For purposes of discussion, we divide Rios into two catagories, those that
147
- have a path and those that don&#8217;t.
148
- </p>
149
- <h4>Creating a <a href="../Rio.html">Rio</a> that has a path</h4>
150
- <p>
151
- To create a <a href="../Rio.html">Rio</a> that has a path the arguments to
152
- <tt>rio</tt> may be:
153
- </p>
154
- <ul>
155
- <li>a string representing the entire path. The separator used for Rios is as
156
- specified in RFC1738 (&#8217;/&#8217;).
157
-
158
- <pre>
159
- rio('adir/afile')
160
- </pre>
161
- </li>
162
- <li>a string representing a fully qualified <tt>file</tt> URI as per RFC1738
163
-
164
- <pre>
165
- rio('file:///atopleveldir/adir/afile')
166
- </pre>
167
- </li>
168
- <li>a <tt>URI</tt> object representing a <tt>file</tt> or generic <tt>URI</tt>
169
-
170
- <pre>
171
- rio(URI('adir/afile'))
172
- </pre>
173
- </li>
174
- <li>the components of a path as separate arguments
175
-
176
- <pre>
177
- rio('adir','afile')
178
- </pre>
179
- </li>
180
- <li>the components of a path as an array
181
-
182
- <pre>
183
- rio(%w/adir afile/)
184
- </pre>
185
- </li>
186
- <li>another <a href="../Rio.html">Rio</a>
187
-
188
- <pre>
189
- another_rio = rio('adir/afile')
190
- rio(another_rio)
191
- </pre>
192
- </li>
193
- <li>any object whose <tt>to_s</tt> method returns one of the above
194
-
195
- <pre>
196
- rio(Pathname.new('apath'))
197
- </pre>
198
- </li>
199
- <li>any combination of the above either as separate arguments or as elements of
200
- an array,
201
-
202
- <pre>
203
- another_rio = rio('dir1/dir2')
204
- auri = URI('dir4/dir5)
205
- rio(another_rio,'dir3',auri,'dir6/dir7')
206
- </pre>
207
- </li>
208
- </ul>
209
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a web page</h5>
210
- <p>
211
- To create a <a href="../Rio.html">Rio</a> that refers to a web page the
212
- arguments to <tt>rio</tt> may be:
213
- </p>
214
- <ul>
215
- <li>a string representing a fully qualified <tt>http</tt> URI
216
-
217
- <pre>
218
- rio('http://ruby-doc.org/index.html')
219
- </pre>
220
- </li>
221
- <li>a <tt>URI</tt> object representing a <tt>http</tt> <tt>URI</tt>
222
-
223
- <pre>
224
- rio(URI('http://ruby-doc.org/index.html'))
225
- </pre>
226
- </li>
227
- <li>either of the above with additional path elements
228
-
229
- <pre>
230
- rio('http://www.ruby-doc.org/','core','classes/Object.html')
231
- </pre>
232
- </li>
233
- </ul>
234
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a file or directory on a FTP server</h5>
235
- <p>
236
- To create a <a href="../Rio.html">Rio</a> that refers to a file on a FTP
237
- server the arguments to <tt>rio</tt> may be:
238
- </p>
239
- <ul>
240
- <li>a string representing a fully qualified <tt>ftp</tt> URI
241
-
242
- <pre>
243
- rio('ftp://user:password@ftp.example.com/afile.tar.gz')
244
- </pre>
245
- </li>
246
- <li>a <tt>URI</tt> object representing a <tt>ftp</tt> <tt>URI</tt>
247
-
248
- <pre>
249
- rio(URI('ftp://ftp.example.com/afile.tar.gz'))
250
- </pre>
251
- </li>
252
- <li>either of the above with additional path elements
253
-
254
- <pre>
255
- rio('ftp://ftp.gnu.org/pub/gnu','emacs','windows','README')
256
- </pre>
257
- </li>
258
- </ul>
259
- <h4>Creating Rios that do not have a path</h4>
260
- <p>
261
- To create a <a href="../Rio.html">Rio</a> without a path, the first
262
- argument to <tt>rio</tt> is usually a single character.
263
- </p>
264
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a clone of your programs stdin or stdout.</h5>
265
- <p>
266
- <tt>rio(?-)</tt> (mnemonic: &#8217;-&#8217; is used by some Unix programs
267
- to specify stdin or stdout in place of a file)
268
- </p>
269
- <p>
270
- Just as a <a href="../Rio.html">Rio</a> that refers to a file, does not
271
- know whether that file will be opened for reading or writing until an io
272
- operation is specified, a <tt>stdio:</tt> <a href="../Rio.html">Rio</a>
273
- does not know whether it will connect to stdin or stdout until an I/O
274
- operation is specified.
275
- </p>
276
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a clone of your programs stderr.</h5>
277
- <p>
278
- <tt>rio(?=)</tt> (mnemonic: &#8217;-&#8217; refers to fileno 1, so
279
- &#8217;=&#8217; refers to fileno 2)
280
- </p>
281
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to an arbitrary IO object.</h5>
282
- <pre>
283
- an_io = ::File.new('afile')
284
- rio(an_io)
285
- </pre>
286
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a file descriptor</h5>
287
- <p>
288
- <tt>rio(?#,fd)</tt> (mnemonic: a file descriptor is a number
289
- &#8217;#&#8217; )
290
- </p>
291
- <pre>
292
- an_io = ::File.new('afile')
293
- rio(an_io)
294
- </pre>
295
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a StringIO object</h5>
296
- <p>
297
- <tt>rio(?&quot;)</tt> (mnemonic: &#8217;&quot;&#8217; surrounds strings)
298
- </p>
299
- <ul>
300
- <li>create a <a href="../Rio.html">Rio</a> that refers to its own string
301
-
302
- </li>
303
- </ul>
304
- <pre>
305
- rio(?&quot;)
306
- </pre>
307
- <ul>
308
- <li>create a <a href="../Rio.html">Rio</a> that refers to a string of your
309
- choosing
310
-
311
- </li>
312
- </ul>
313
- <pre>
314
- astring = &quot;&quot;
315
- rio(?&quot;,&quot;&quot;)
316
- </pre>
317
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to a Temporary object</h5>
318
- <p>
319
- <tt>rio(??)</tt> (mnemonic: &#8217;?&#8217; you don&#8217;t know its name)
320
- </p>
321
- <p>
322
- To create a temporary object that will become a file or a directory,
323
- depending on how you use it:
324
- </p>
325
- <pre>
326
- rio(??)
327
- rio(??,basename='rio',tmpdir=Dir::tmpdir)
328
- </pre>
329
- <p>
330
- To force it to become a file
331
- </p>
332
- <pre>
333
- rio(??).file
334
- </pre>
335
- <p>
336
- or just write to it.
337
- </p>
338
- <p>
339
- To force it to become a directory:
340
- </p>
341
- <pre>
342
- rio(??).dir
343
- </pre>
344
- <p>
345
- or
346
- </p>
347
- <pre>
348
- rio(??).mkdir
349
- </pre>
350
- <p>
351
- or
352
- </p>
353
- <pre>
354
- rio(??).chdir
355
- </pre>
356
- <h5>Creating a <a href="../Rio.html">Rio</a> that refers to an arbitrary TCPSocket</h5>
357
- <pre>
358
- rio('tcp:',hostname,port)
359
- </pre>
360
- <p>
361
- or
362
- </p>
363
- <pre>
364
- rio('tcp://hostname:port')
365
- </pre>
366
- <h5>Creating a <a href="../Rio.html">Rio</a> that runs an external program and connects to its stdin and stdout</h5>
367
- <p>
368
- <tt>rio(?-,cmd)</tt> (mnemonic: &#8217;-&#8217; is used by some Unix
369
- programs to specify stdin or stdout in place of a file)
370
- </p>
371
- <p>
372
- or
373
- </p>
374
- <p>
375
- <tt>rio(?`,cmd)</tt> (mnemonic: &#8217;`&#8217; (backtick) runs an external
376
- program in ruby)
377
- </p>
378
- <p>
379
- This is <a href="../Rio.html">Rio</a>&#8217;s interface to IO#popen
380
- </p>
381
- <h3>Path Manipulation</h3>
382
- <p>
383
- <a href="../Rio.html">Rio</a>&#8217;s path manipulation methods are for the
384
- most part simply forwarded to the File or URI classes with the return
385
- values converted to a <a href="../Rio.html">Rio</a>.
386
- </p>
387
- <h4>Creating a <a href="../Rio.html">Rio</a> from a <a href="../Rio.html">Rio</a>&#8217;s component parts.</h4>
388
- <p>
389
- The <a href="../Rio.html">Rio</a> methods for creating a <a
390
- href="../Rio.html">Rio</a> from a <a href="../Rio.html">Rio</a>&#8217;s
391
- component parts are <a href="../Rio.html#M000093">Rio#dirname</a>, <a
392
- href="../Rio.html#M000095">Rio#filename</a>, <a
393
- href="../Rio.html#M000092">Rio#basename</a>, and <a
394
- href="../Rio.html#M000094">Rio#extname</a>. The behavior of <a
395
- href="../Rio.html#M000092">Rio#basename</a> depends on the setting of the
396
- <tt>ext</tt> configuration variable and is different from its counterpart
397
- in the File class. The default value of the <tt>ext</tt> configuration
398
- variable is the string returned File#extname. The <tt>ext</tt>
399
- configuration variable can be changed using <a
400
- href="../Rio.html#M000089">Rio#ext</a> and <a
401
- href="../Rio.html#M000090">Rio#noext</a> and can be queried using <a
402
- href="../Rio.html#M000089">Rio#ext</a>?. This value is used by calls to <a
403
- href="../Rio.html#M000092">Rio#basename</a>.
404
- </p>
405
- <p>
406
- <a href="../Rio.html#M000095">Rio#filename</a> returns the last component
407
- of a path, and is basically the same as <tt>basename</tt> without
408
- consideration of an extension. So
409
- </p>
410
- <pre>
411
- rio('afile.txt').basename #=&gt; rio('afile')
412
- rio('afile.txt').filename #=&gt; rio('afile.txt')
413
-
414
- ario = rio('afile.tar.gz')
415
- ario.basename #=&gt; rio('afile.tar')
416
- ario.ext? #=&gt; &quot;.gz&quot;
417
- ario.ext('.tar.gz').basename #=&gt; rio('afile')
418
- ario.ext? #=&gt; &quot;.tar.gz&quot;
419
- </pre>
420
- <h4>Changing a path&#8217;s component parts.</h4>
421
- <p>
422
- <a href="../Rio.html">Rio</a> also provides methods for changing the
423
- component parts of its path. They are <a
424
- href="../Rio.html#M000093">Rio#dirname</a>=, <a
425
- href="../Rio.html#M000095">Rio#filename</a>=, <a
426
- href="../Rio.html#M000092">Rio#basename</a>=, and <a
427
- href="../Rio.html#M000094">Rio#extname</a>=. These methods replace the part
428
- extracted as described above with their argument.
429
- </p>
430
- <pre>
431
- ario = rio('dirA/dirB/afile.rb')
432
- ario.dirname = 'dirC' # rio('dirC/afile.rb')
433
- ario.basename = 'bfile' # rio('dirC/bfile.rb')
434
- ario.extname = '.txt' # rio('dirC/bfile.txt')
435
- ario.filename = 'cfile.rb' # rio('dirC/cfile.rb')
436
- </pre>
437
- <p>
438
- <a href="../Rio.html">Rio</a> also has a <tt>rename</tt> mode which causes
439
- each of these to rename the actual file system object as well as changing
440
- the <a href="../Rio.html">Rio</a>. This is discussed in the section on
441
- Renaming and Moving.
442
- </p>
443
- <h4>Splitting a <a href="../Rio.html">Rio</a></h4>
444
- <p>
445
- <a href="../Rio.html#M000101">Rio#split</a> returns an array of Rios, one
446
- for each path element. (Note that this behavior differs from File#split.)
447
- </p>
448
- <pre>
449
- rio('a/b/c').split #=&gt; [rio('a'),rio('b'),rio('c')]
450
- </pre>
451
- <p>
452
- The array returned is extended with a <tt>to_rio</tt> method, which will
453
- put the parts back together again.
454
- </p>
455
- <pre>
456
- ary = rio('a/b/c').split #=&gt; [rio('a'),rio('b'),rio('c')]
457
- ary.to_rio #=&gt; rio('a/b/c')
458
- </pre>
459
- <h4>Creating a <a href="../Rio.html">Rio</a> by specifying the individual parts of its path</h4>
460
- <p>
461
- The first way to create a <a href="../Rio.html">Rio</a> by specifying its
462
- parts is to use the <a href="../Rio.html">Rio</a> constructor <a
463
- href="../Rio.html#M000006">Rio#rio</a>. Since a <a
464
- href="../Rio.html">Rio</a> is among the arguments the constructor will
465
- take, the constructor can be used.
466
- </p>
467
- <pre>
468
- ario = rio('adir')
469
- rio(ario,'b') #=&gt; rio('adir/b')
470
- </pre>
471
- <p>
472
- <a href="../Rio.html#M000100">Rio#join</a> and <a
473
- href="../Rio.html">Rio</a>#/ do the same thing, but the operator version
474
- <tt>/</tt> can take only one argument.
475
- </p>
476
- <pre>
477
- a = rio('a')
478
- b = rio('b')
479
- c = a.join(b) #=&gt; rio('a/b')
480
- c = a/b #=&gt; rio('a/b')
481
- </pre>
482
- <p>
483
- The arguments to <tt>join</tt> and <tt>/</tt> do not need to be Rios, of
484
- course
485
- </p>
486
- <pre>
487
- ario = rio('adir')
488
- ario/'afile.rb' #=&gt; rio('ario/afile.rb')
489
- ario.join('b','c','d') #=&gt; rio('ario/b/c/d')
490
- ario/'b'/'c'/'d' #=&gt; rio('ario/b/c/d')
491
- ario /= 'e' #=&gt; rio('ario/b/c/d/e')
492
- </pre>
493
- <h4>Manipulating a <a href="../Rio.html">Rio</a> path by treating it as a string.</h4>
494
- <p>
495
- The <a href="../Rio.html">Rio</a> methods which treat a <a
496
- href="../Rio.html">Rio</a> as a string are <a
497
- href="../Rio.html#M000104">Rio#sub</a>, <a
498
- href="../Rio.html#M000105">Rio#gsub</a> and <a
499
- href="../Rio.html">Rio</a>#+. These methods create a new <a
500
- href="../Rio.html">Rio</a> using the string created by forwarding the
501
- method to the String returned by <a
502
- href="../Rio.html#M000008">Rio#to_s</a>.
503
- </p>
504
- <pre>
505
- ario = rio('dirA/dirB/afile') + '-1.1.1' # rio('dirA/dirB/afile-1.1.1')
506
- brio = ario.sub(/^dirA/, 'dirC') # rio('dirC/dirB/afile-1.1.1')
507
- </pre>
508
- <h4>Creating a <a href="../Rio.html">Rio</a> based on its relationship to another</h4>
509
- <p>
510
- <a href="../Rio.html#M000086">Rio#abs</a> creates a new rio whose path is
511
- the absolute path of a <a href="../Rio.html">Rio</a>. If provided with an
512
- argument, it uses that as the base path, otherwise it uses an internal base
513
- path (usually the current working directory when it was created).
514
- </p>
515
- <pre>
516
- rio('/tmp').chdir do
517
- rio('a').abs #=&gt; rio('/tmp/a')
518
- rio('a').abs('/usr') #=&gt; rio('/usr/a')
519
- end
520
- </pre>
521
- <p>
522
- <a href="../Rio.html#M000087">Rio#rel</a> creates a new rio with a path
523
- relative to a <a href="../Rio.html">Rio</a>.
524
- </p>
525
- <pre>
526
- rio('/tmp').chdir do
527
- rio('/tmp/a').rel #=&gt; rio('a')
528
- end
529
- rio('/tmp/b').rel('/tmp') #=&gt; rio('b')
530
- </pre>
531
- <p>
532
- <a href="../Rio.html#M000113">Rio#route_to</a> and <a
533
- href="../Rio.html#M000112">Rio#route_from</a> creates a new rio with a path
534
- representing the route to get to/from a <a href="../Rio.html">Rio</a>. They
535
- are based on the methods of the same names in the URI class
536
- </p>
537
- <h3>Configuring a <a href="../Rio.html">Rio</a></h3>
538
- <p>
539
- The second step in using a rio is configuring it. Note that many times no
540
- configuration is necessary and that this is not a comprehensive list of all
541
- of <a href="../Rio.html">Rio</a>&#8217;s configuration methods.
542
- </p>
543
- <p>
544
- <a href="../Rio.html">Rio</a>&#8217;s configuration mehods fall into three
545
- categories.
546
- </p>
547
- <dl>
548
- <dt>IO manipulators</dt><dd>An IO manipulator alters the behavior of a <a
549
- href="../Rio.html">Rio</a>&#8217;s underlying IO object. These affect the
550
- behaviour of I/O methods which are forwarded directly to the underlying
551
- object as well as the grande I/O methods.
552
-
553
- </dd>
554
- <dt>Grande configuration methods</dt><dd>The grande configuration methods affect the behaviour of <a
555
- href="../Rio.html">Rio</a>&#8217;s grande I/O methods
556
-
557
- </dd>
558
- <dt>Grande selection methods</dt><dd>The grande selection methods select what data is returned by <a
559
- href="../Rio.html">Rio</a>&#8217;s grande I/O methods
560
-
561
- </dd>
562
- </dl>
563
- <p>
564
- All of <a href="../Rio.html">Rio</a>&#8217;s configuration and selection
565
- methods can be passed a block, which will cause the <a
566
- href="../Rio.html">Rio</a> to behave as if <tt>each</tt> had been called
567
- with the block after the method.
568
- </p>
569
- <h4>IO manipulators</h4>
570
- <ul>
571
- <li><tt>gzip</tt> a file on output, and ungzip it on input
572
-
573
- <pre>
574
- rio('afile.gz').gzip
575
- </pre>
576
- <p>
577
- This causes the rio to read through a Zlib::GzipReader and to write
578
- Zlib::GzipWriter.
579
- </p>
580
- </li>
581
- <li><tt>chomp</tt> lines as they are read
582
-
583
- <pre>
584
- rio('afile').chomp
585
- </pre>
586
- <p>
587
- This causes a <a href="../Rio.html">Rio</a> to call String#chomp on the the
588
- String returned by all line oriented read operations.
589
- </p>
590
- </li>
591
- </ul>
592
- <h4>Grande configuration methods</h4>
593
- <ul>
594
- <li><tt>all</tt>, <tt>recurse</tt>, <tt>norecurse</tt>
595
-
596
- <pre>
597
- rio('adir').all
598
- rio('adir').norecurse('CVS')
599
- </pre>
600
- <p>
601
- These methods instruct the <a href="../Rio.html">Rio</a> to also include
602
- entries in subdirectories when iterating through directories and control
603
- which subdirectories are included or excluded.
604
- </p>
605
- </li>
606
- <li><tt>bytes</tt>
607
-
608
- <pre>
609
- rio('afile').bytes(1024)
610
- </pre>
611
- <p>
612
- This causes a <a href="../Rio.html">Rio</a> to read the specified number of
613
- bytes at a time as a file is iterated through.
614
- </p>
615
- </li>
616
- </ul>
617
- <h4>Grande selection methods</h4>
618
- <ul>
619
- <li><tt>lines</tt>, <tt>nolines</tt>
620
-
621
- <pre>
622
- rio('afile').lines(0..9)
623
- rio('afile').nolines(/^\s*#/)
624
- </pre>
625
- <p>
626
- Strictly speaking these are both configuration and selection methods. They
627
- configure the <a href="../Rio.html">Rio</a> to iterate through an input
628
- stream as lines. The arguments select which lines are actually returned.
629
- Lines are included (<tt>lines</tt>) or excluded (<tt>nolines</tt>) if they
630
- match <b>any</b> of the arguments as follows.
631
- </p>
632
- <p>
633
- If the argument is a:
634
- </p>
635
- <table>
636
- <tr><td valign="top"><tt>RegExp</tt>:</td><td>the line is matched against it
637
-
638
- </td></tr>
639
- <tr><td valign="top"><tt>Range</tt>:</td><td>the lineno is matched against it
640
-
641
- </td></tr>
642
- <tr><td valign="top"><tt>Integer</tt>:</td><td>the lineno is matched against it as if it were a one element range
643
-
644
- </td></tr>
645
- <tr><td valign="top"><tt>Symbol</tt>:</td><td>the symbol is <tt>sent</tt> to the string; the line is included unless it
646
- returns false
647
-
648
- </td></tr>
649
- <tr><td valign="top"><tt>Proc</tt>:</td><td>the proc is called with the line as an argument; the line is included
650
- unless it returns false
651
-
652
- </td></tr>
653
- </table>
654
- </li>
655
- <li><tt>entries</tt>, <tt>files</tt>, <tt>dirs</tt>, <tt>noentries</tt>,
656
- <tt>nofiles</tt>, <tt>nodirs</tt>
657
-
658
- <pre>
659
- rio('adir').files('*.txt')
660
- rio('adir').nofiles(/^\./)
661
- </pre>
662
- <p>
663
- These methods select which entries will be returned when iterating throug
664
- directories. Entries are included
665
- (<tt>entries</tt>,<tt>files</tt>,<tt>dirs</tt>) or
666
- excluded(<tt>noentries</tt>,<tt>nofiles</tt>,<tt>nodirs</tt>) if they match
667
- <b>any</b> of the arguments as follows.
668
- </p>
669
- <p>
670
- If the argument is a:
671
- </p>
672
- <table>
673
- <tr><td valign="top"><tt>String</tt>:</td><td>the arg is treated as a glob; the filname is matched against it
674
-
675
- </td></tr>
676
- <tr><td valign="top"><tt>RegExp</tt>:</td><td>the filname is matched against it
677
-
678
- </td></tr>
679
- <tr><td valign="top"><tt>Symbol</tt>:</td><td>the symbol is <tt>sent</tt> to the entry (a <a href="../Rio.html">Rio</a>);
680
- the entry is included unless it returns false
681
-
682
- </td></tr>
683
- <tr><td valign="top"><tt>Proc</tt>:</td><td>the proc is called with the entry (a <a href="../Rio.html">Rio</a>) as an
684
- argument; the entry is included unless it returns false
685
-
686
- </td></tr>
687
- </table>
688
- </li>
689
- <li><tt>records</tt>, <tt>rows</tt>, <tt>norecords</tt>, <tt>norows</tt>
690
-
691
- <pre>
692
- rio('afile').bytes(1024).records(0...10)
693
- </pre>
694
- <p>
695
- These select items from an input stream just as <tt>lines</tt>, but without
696
- specifying lines as the input record type. They can be used to select
697
- different record types in extension modules. The only such module at this
698
- writing is the CSV extension. In that case <tt>records</tt> causes each
699
- line of a CSV file to be parsed into an array while <tt>lines</tt> causes
700
- each line of the file to be returned normally.
701
- </p>
702
- </li>
703
- </ul>
704
- <h3><a href="../Rio.html">Rio</a> I/O</h3>
705
- <p>
706
- As stated above the the three steps to using a <a
707
- href="../Rio.html">Rio</a> are:
708
- </p>
709
- <ul>
710
- <li>Creating a <a href="../Rio.html">Rio</a>
711
-
712
- </li>
713
- <li>Configuring a <a href="../Rio.html">Rio</a>
714
-
715
- </li>
716
- <li>Doing I/O
717
-
718
- </li>
719
- </ul>
720
- <p>
721
- This section describes that final step.
722
- </p>
723
- <p>
724
- After creating and configuring a <a href="../Rio.html">Rio</a>, the
725
- file-system has not been accessed, no socket has been opened, not so much
726
- as a test for a files existance has been done. When an I/O method is called
727
- on a <a href="../Rio.html">Rio</a>, the sequence of events required to
728
- complete that operation on the underlying object takes place. <a
729
- href="../Rio.html">Rio</a> takes care of creating the apropriate object (eg
730
- IO,Dir), opening the object with the apropriate mode, performing the
731
- operation, closing the object if required, and returning the results of the
732
- operation.
733
- </p>
734
- <p>
735
- <a href="../Rio.html">Rio</a>&#8217;s I/O operations can be divide into two
736
- catagories:
737
- </p>
738
- <ul>
739
- <li>Proxy operations
740
-
741
- </li>
742
- <li>Grande operations
743
-
744
- </li>
745
- </ul>
746
- <h4>Proxy operations</h4>
747
- <p>
748
- These are calls which are forwarded to the underlying object (eg
749
- IO,Dir,Net::FTP), after apropriately creating and configuring that object.
750
- The result produced by the method is returned, and the object is closed.
751
- </p>
752
- <p>
753
- In some cases the result is modified before being returned, as when a <a
754
- href="../Rio.html">Rio</a> is configured with <tt>chomp</tt>.
755
- </p>
756
- <p>
757
- In all cases, if the result returned by the underlying object, could itself
758
- be used for further I/O operations it is returned as a <a
759
- href="../Rio.html">Rio</a>. For example: where File#dirname returns a
760
- string, <a href="../Rio.html#M000093">Rio#dirname</a> returns a <a
761
- href="../Rio.html">Rio</a>; where Dir#read returns a string representing a
762
- directory entry, <a href="../Rio.html#M000038">Rio#read</a> returns a <a
763
- href="../Rio.html">Rio</a>.
764
- </p>
765
- <p>
766
- With some noteable exceptions, most of the operations available if one were
767
- using the underlying Ruby I/O class are available to the <a
768
- href="../Rio.html">Rio</a> and will behave identically.
769
- </p>
770
- <p>
771
- For things that exist on a file system:
772
- </p>
773
- <ul>
774
- <li>All the methods in FileTest are available as <a href="../Rio.html">Rio</a>
775
- instance methods. For example
776
-
777
- <pre>
778
- FileTest.file?('afile')
779
- </pre>
780
- <p>
781
- becomes
782
- </p>
783
- <pre>
784
- rio('afile').file?
785
- </pre>
786
- </li>
787
- <li>All the instance methods of <tt>File</tt> except <tt>path</tt> are
788
- available to a rio without change
789
-
790
- </li>
791
- <li>Most of the class methods of <tt>File</tt> are available.
792
-
793
- <ul>
794
- <li>For those that take a filename as their only argument the calls are mapped
795
- to <a href="../Rio.html">Rio</a> instance methods as described above for
796
- FileTest.
797
-
798
- </li>
799
- <li><tt>dirname</tt>, and <tt>readlink</tt> return Rios instead of strings
800
-
801
- </li>
802
- <li><a href="../Rio.html">Rio</a> has its own <a
803
- href="../Rio.html#M000092">Rio#basename</a>, <a
804
- href="../Rio.html#M000100">Rio#join</a> and <a
805
- href="../Rio.html#M000035">Rio#symlink</a>, which provide similar
806
- functionality.
807
-
808
- </li>
809
- <li>The class methods which take multiple filenames
810
- (<tt>chmod</tt>,<tt>chown</tt>,<tt>lchmod</tt>,<tt>lchown</tt>) are
811
- available as <a href="../Rio.html">Rio</a> instance methods. For example
812
-
813
- <pre>
814
- File.chmod(0666,'afile')
815
- </pre>
816
- <p>
817
- becomes
818
- </p>
819
- <pre>
820
- rio('afile').chmod(06660)
821
- </pre>
822
- </li>
823
- </ul>
824
- </li>
825
- </ul>
826
- <p>
827
- For I/O Streams
828
- </p>
829
- <p>
830
- Most of the instance methods of IO are available, and most do the same
831
- thing, with some interface changes. <b>The big exception to this is the
832
- &#8217;&lt;&lt;&#8217; operator.</b> This is one of <a
833
- href="../Rio.html">Rio</a>&#8217;s grande operators. While the symantics
834
- one would use to write to an IO object would actually accomplish the same
835
- thing with a <a href="../Rio.html">Rio</a>, It is a very different
836
- operator. Read the section on grande operators. The other differences
837
- between IO instance methods and the <a href="../Rio.html">Rio</a>
838
- equivelence can be summarized as follows.
839
- </p>
840
- <ul>
841
- <li>The simple instance methods (eg <tt>fcntl</tt>, <tt>eof?</tt>,
842
- <tt>tty?</tt> etc.) are forwarded and the result returned as is
843
-
844
- </li>
845
- <li>Anywhere IO returns an IO, <a href="../Rio.html">Rio</a> returns a <a
846
- href="../Rio.html">Rio</a>
847
-
848
- </li>
849
- <li><tt>close</tt> and its cousins return the <a href="../Rio.html">Rio</a>.
850
-
851
- </li>
852
- <li><tt>each_byte</tt> and <tt>each_line</tt> are forwarded as is.
853
-
854
- </li>
855
- <li>All methods which read (read*,get*,each*) will cause the file to closed
856
- when the end of file is reached. This behavior is configurable, but the
857
- default is to close on eof
858
-
859
- </li>
860
- <li>The methods which write (put*,print*) are forwarded as is; put* and print*
861
- return the <a href="../Rio.html">Rio</a>; write returns the value returned
862
- by IO#write; as mentioned above &#8217;&lt;&lt;&#8217; is a grande operator
863
- in <a href="../Rio.html">Rio</a>.
864
-
865
- </li>
866
- </ul>
867
- <p>
868
- For directories:
869
- </p>
870
- <ul>
871
- <li>all the instance methods of Dir are available except <tt>each</tt> which is
872
- a grande method.
873
-
874
- </li>
875
- <li>the class methods <tt>mkdir</tt>, <tt>delete</tt>, <tt>rmdir</tt> are
876
- provided as instance methods.
877
-
878
- </li>
879
- <li><tt>chdir</tt> is provided as an instance method. <a
880
- href="../Rio.html#M000017">Rio#chdir</a> returns a <a
881
- href="../Rio.html">Rio</a> and passes a <a href="../Rio.html">Rio</a> to a
882
- block if one is provided.
883
-
884
- </li>
885
- <li><tt>glob</tt> is provided as an instance method, but returns an array of
886
- Rios
887
-
888
- </li>
889
- <li><tt>foreach</tt> is not supported
890
-
891
- </li>
892
- <li><tt>each</tt> and <tt>[]</tt> have similar functionality provided by <a
893
- href="../Rio.html">Rio</a>
894
-
895
- </li>
896
- </ul>
897
- <p>
898
- For other Rios, instance methods are generally forwarded where appropriate.
899
- For example
900
- </p>
901
- <ul>
902
- <li>Rios that refer to StringIO objects forward &#8216;string&#8217; and
903
- &#8216;string=&#8217;
904
-
905
- </li>
906
- <li>Rios that refer to http URIs support all the Meta methods provided by
907
- open-uri
908
-
909
- </li>
910
- </ul>
911
- <h4>Grande operators</h4>
912
- <p>
913
- The primary grande operator is <a href="../Rio.html#M000045">Rio#each</a>.
914
- <tt>each</tt> is used to iterate through Rios. When applied to a file it
915
- iterates through records in the file. When applied to a directory it
916
- iterates through the entries in the directory. Its behavior is modified by
917
- configuring the <a href="../Rio.html">Rio</a> prior to calling it using the
918
- configuration methods discussed above. Since iterating through things is
919
- ubiquitous in ruby, it is implied by the presence of a block after any of
920
- the grande configuration methods and many times does not need to be call
921
- explicitly. For example:
922
- </p>
923
- <pre>
924
- rio('afile.rb').chomp.lines(/^\s*#/) { |line| ... } # iterate through chomped ruby comment lines
925
- rio('adir').all.files('*.rb') { |f| ... } # iterate through all .rb files in 'adir' and its subdirectories
926
- </pre>
927
- <p>
928
- Because a <a href="../Rio.html">Rio</a> is an Enumerable, it supports
929
- <tt>to_a</tt>, which is the basis for the grande subscript operator. <a
930
- href="../Rio.html">Rio</a>#[] with no arguments simply calls to_a. With
931
- arguments it behaves as if those arguments had been passed to the most
932
- recently called of the grande selection methods listed above, and then
933
- calls to_a. For example to get the first ten lines of a file into an array
934
- with lines chomped
935
- </p>
936
- <pre>
937
- rio('afile').chomp.lines(0...10).to_a
938
- </pre>
939
- <p>
940
- can be written as
941
- </p>
942
- <pre>
943
- rio('afile.gz').chomp.lines[0...10]
944
- </pre>
945
- <p>
946
- or, to create an array of all the .c files in a directory, one could write
947
- </p>
948
- <pre>
949
- rio('adir').files['*.c']
950
- </pre>
951
- <p>
952
- The other grande operators are its copy operators. They are:
953
- </p>
954
- <ul>
955
- <li><tt>&lt;</tt> (copy-from)
956
-
957
- </li>
958
- <li><tt>&lt;&lt;</tt> (append-from)
959
-
960
- </li>
961
- <li><tt>&gt;</tt> (copy-to)
962
-
963
- </li>
964
- <li><tt>&gt;&gt;</tt> (append-to)
965
-
966
- </li>
967
- </ul>
968
- <p>
969
- The only difference between the &#8216;copy&#8217; and &#8216;append&#8217;
970
- versions is how they deal with an unopened resource. In the former the open
971
- it with mode &#8216;w&#8217; and in the latter, mode &#8216;a&#8217;.
972
- Beyond that, their behavior can be summarized as:
973
- </p>
974
- <pre>
975
- source.each do |entry|
976
- destination &lt;&lt; entry
977
- end
978
- </pre>
979
- <p>
980
- Since they are based on the <tt>each</tt> operator, all of the selection
981
- and configuration options are available. And the right-hand-side argument
982
- of the operators are not restricted to Rios &#8212; Strings and Arrays are
983
- also supported.
984
- </p>
985
- <p>
986
- For example:
987
- </p>
988
- <pre>
989
- rio('afile') &gt; astring # copy a file into a string
990
-
991
- rio('afile').chomp &gt; anarray # copy the chomped lines of afile into an array
992
-
993
- rio('afile.gz').gzip.lines(0...100) &gt; rio('bfile') # copy 100 lines from a gzipped file into another file
994
-
995
- rio(?-) &lt; rio('http://rubydoc.org/') # copy a web page to stdout
996
-
997
- rio('bdir') &lt; rio('adir') # copy an entire directory structure
998
-
999
- rio('adir').dirs.files('README') &gt; rio('bdir') # same thing, but only README files
1000
-
1001
- rio(?-,'ps -a').nolines(0,/ps$/) &gt; anarray # copy the output of th ps command into an array, skippying
1002
- # the header line and the ps command entry
1003
- </pre>
1004
- <h3>Renaming and Moving</h3>
1005
- <p>
1006
- <a href="../Rio.html">Rio</a> provides two methods for directly renaming
1007
- objects on the filesystem: <a href="../Rio.html#M000037">Rio#rename</a> and
1008
- <a href="../Rio.html#M000037">Rio#rename</a>!. Both of these use
1009
- File#rename. The difference between them is the returned <a
1010
- href="../Rio.html">Rio</a>. <a href="../Rio.html#M000037">Rio#rename</a>
1011
- leaves the path of the <a href="../Rio.html">Rio</a> unchanged, while <a
1012
- href="../Rio.html#M000037">Rio#rename</a>! changes the path of the <a
1013
- href="../Rio.html">Rio</a> to refer to the renamed path.
1014
- </p>
1015
- <pre>
1016
- ario = rio('a')
1017
- ario.rename('b') # file 'a' has been renamed to 'b' but 'ario' =&gt; rio('a')
1018
- ario.rename!('b') # file 'a' has been renamed to 'b' and 'ario' =&gt; rio('b')
1019
- </pre>
1020
- <p>
1021
- <a href="../Rio.html">Rio</a> also has a <tt>rename</tt> mode, which causes
1022
- the path manipulation methods <a
1023
- href="../Rio.html#M000093">Rio#dirname</a>=, <a
1024
- href="../Rio.html#M000095">Rio#filename</a>=, <a
1025
- href="../Rio.html#M000092">Rio#basename</a>= and <a
1026
- href="../Rio.html#M000094">Rio#extname</a>= to rename an object on the
1027
- filesystem when they are used to change a <a
1028
- href="../Rio.html">Rio</a>&#8217;s path. A <a href="../Rio.html">Rio</a> is
1029
- put in <tt>rename</tt> mode by calling <a
1030
- href="../Rio.html#M000037">Rio#rename</a> with no arguments.
1031
- </p>
1032
- <pre>
1033
- rio('adir/afile.txt').rename.filename = 'bfile.rb' # adir/afile.txt =&gt; adir/bfile.rb
1034
- rio('adir/afile.txt').rename.basename = 'bfile' # adir/afile.txt =&gt; adir/bfile.txt
1035
- rio('adir/afile.txt').rename.extname = '.rb' # adir/afile.txt =&gt; adir/afile.rb
1036
- rio('adir/afile.txt').rename.dirname = 'b/c' # adir/afile.txt =&gt; b/c/afile.txt
1037
- </pre>
1038
- <p>
1039
- When <tt>rename</tt> mode is set for a directory <a
1040
- href="../Rio.html">Rio</a>, it is automatically set in the Rios created
1041
- when iterating through that directory.
1042
- </p>
1043
- <pre>
1044
- rio('adir').rename.files('*.htm') do |frio|
1045
- frio.extname = '.html' #=&gt; changes the rio and renames the file
1046
- end
1047
- </pre>
1048
- <h3>Deleting</h3>
1049
- <p>
1050
- The <a href="../Rio.html">Rio</a> methods for deleting filesystem objects
1051
- are <a href="../Rio.html#M000033">Rio#rm</a>, <a
1052
- href="../Rio.html#M000029">Rio#rmdir</a>, <a
1053
- href="../Rio.html#M000030">Rio#rmtree</a>, <a
1054
- href="../Rio.html#M000046">Rio#delete</a>, and <a
1055
- href="../Rio.html#M000046">Rio#delete</a>!. <tt>rm</tt>, <tt>rmdir</tt> and
1056
- <tt>rmtree</tt> are passed the like named methods in the FileUtils module.
1057
- <a href="../Rio.html#M000046">Rio#delete</a> calls <tt>rmdir</tt> for
1058
- directories and <tt>rm</tt> for anything else, while <a
1059
- href="../Rio.html#M000046">Rio#delete</a>! calls <a
1060
- href="../Rio.html#M000030">Rio#rmtree</a> for directories.
1061
- </p>
1062
- <ul>
1063
- <li>To delete something only if it is not a directory use <a
1064
- href="../Rio.html#M000033">Rio#rm</a>
1065
-
1066
- </li>
1067
- <li>To delete an empty directory use <a
1068
- href="../Rio.html#M000029">Rio#rmdir</a>
1069
-
1070
- </li>
1071
- <li>To delete an entire directory tree use <a
1072
- href="../Rio.html#M000030">Rio#rmtree</a>
1073
-
1074
- </li>
1075
- <li>To delete anything except a populated directory use <a
1076
- href="../Rio.html#M000046">Rio#delete</a>
1077
-
1078
- </li>
1079
- <li>To delete anything use <a href="../Rio.html#M000046">Rio#delete</a>!
1080
-
1081
- </li>
1082
- </ul>
1083
- <p>
1084
- It is not an error to call any of the deleting methods on something that
1085
- does not exist. <a href="../Rio.html">Rio</a> provides Rio#exist? and <a
1086
- href="../Rio.html#M000035">Rio#symlink</a>? to check if something exists
1087
- (<tt>exist?</tt> returns false for symlinks to non-existant object even
1088
- though the symlink itself exists). The deleting methods&#8217; purpose is
1089
- to make things not exist, so calling one of them on something that already
1090
- does not exist is considered a success.
1091
- </p>
1092
- <p>
1093
- To create a clean copy of a directory whether or not anything with that
1094
- name exists one might do this
1095
- </p>
1096
- <pre>
1097
- rio('adir').delete!.mkpath.chdir do
1098
- # do something in adir
1099
- end
1100
- </pre>
1101
- <hr size="1"></hr><h2>Miscellany</h2>
1102
- <h4>Using Symbolic Links</h4>
1103
- <p>
1104
- To create a symbolic link (symlink) to the file-system entry refered to by
1105
- a <a href="../Rio.html">Rio</a>, use <a
1106
- href="../Rio.html#M000035">Rio#symlink</a>. <a
1107
- href="../Rio.html#M000035">Rio#symlink</a> differs from File#symlink in
1108
- that it calculates the path from the symlink location to the <a
1109
- href="../Rio.html">Rio</a>&#8217;s position. So:
1110
- </p>
1111
- <pre>
1112
- File#symlink('adir/afile','adir/alink')
1113
- </pre>
1114
- <p>
1115
- creates a symlink in the directory &#8216;adir&#8217; named
1116
- &#8216;alink&#8217; which references &#8216;adir/afile&#8217;. From the
1117
- perspective of &#8216;alink&#8217;, &#8216;adir/afile&#8217; does not
1118
- exist. While:
1119
- </p>
1120
- <pre>
1121
- rio('adir/afile').symlink('adir/alink')
1122
- </pre>
1123
- <p>
1124
- creates a symlink in the directory &#8216;adir&#8217; named
1125
- &#8216;alink&#8217; which references &#8216;afile&#8217;. This is the route
1126
- to &#8216;adir/afile&#8217; from the perspective of
1127
- &#8216;adir/alink&#8217;.
1128
- </p>
1129
- <p>
1130
- Note that the return value from <tt>symlink</tt> is the calling <a
1131
- href="../Rio.html">Rio</a> and not a <a href="../Rio.html">Rio</a> refering
1132
- to the symlink. This is done for consistency with the rest of <a
1133
- href="../Rio.html">Rio</a>.
1134
- </p>
1135
- <p>
1136
- <a href="../Rio.html#M000035">Rio#symlink</a>? can be used to test if a
1137
- file-system object is a symlink. A <a href="../Rio.html">Rio</a> is
1138
- extended with <a href="../Rio.html#M000036">Rio#readlink</a>, and <a
1139
- href="../Rio.html#M000161">Rio#lstat</a> only if <a
1140
- href="../Rio.html#M000035">Rio#symlink</a>? returns true. So for
1141
- non-symlinks, these will raise a NoMethodError. These are both passed to
1142
- their counterparts in File. <a href="../Rio.html#M000036">Rio#readlink</a>
1143
- returns a <a href="../Rio.html">Rio</a> refering to the result of
1144
- File#readlink.
1145
- </p>
1146
- <h4>Using A <a href="../Rio.html">Rio</a> as an IO (or File or Dir)</h4>
1147
- <p>
1148
- <a href="../Rio.html">Rio</a> supports so much of IO&#8217;s interface that
1149
- one might be tempted to pass it to a method that expects an IO. While <a
1150
- href="../Rio.html">Rio</a> is not and is not intended to be a stand in for
1151
- IO, this can work. It requires knowledge of every IO method that will be
1152
- called, under any circumstances.
1153
- </p>
1154
- <p>
1155
- Even in cases where <a href="../Rio.html">Rio</a> supports the required IO
1156
- interface, A <a href="../Rio.html">Rio</a> feature that seems to cause the
1157
- most incompatibility, is its automatic closing of files. To turn off all of
1158
- <a href="../Rio.html">Rio</a>&#8217;s automatic closing use
1159
- Rio#noautoclose.
1160
- </p>
1161
- <p>
1162
- For example:
1163
- </p>
1164
- <pre>
1165
- require 'yaml'
1166
- yrio = rio('ran.yaml').delete!.noautoclose
1167
- YAML.dump( ['badger', 'elephant', 'tiger'], yrio )
1168
- obj = YAML::load( yrio ) #=&gt; [&quot;badger&quot;, &quot;tiger&quot;, &quot;elephant&quot;]
1169
- </pre>
1170
- <h4>Automatic Closing of Files</h4>
1171
- <p>
1172
- <a href="../Rio.html">Rio</a> closes files automatically in three
1173
- instances.
1174
- </p>
1175
- <p>
1176
- When reading from an IO it is closed when the end of file is reached. While
1177
- this is a reasonable thing to do in many cases, sometimes this is not
1178
- desired. To turn <a href="../Rio.html">Rio</a>&#8217;s automatic closing on
1179
- end of file use <a href="../Rio.html#M000069">Rio#nocloseoneof</a> (it can
1180
- be turned back on via <a href="../Rio.html#M000068">Rio#closeoneof</a>)
1181
- </p>
1182
- <pre>
1183
- ario = rio('afile').nocloseoneof
1184
- lines = ario[]
1185
- ario.closed? #=&gt; false
1186
- </pre>
1187
- <p>
1188
- Closing on end-of-file is necessary for many of <a
1189
- href="../Rio.html">Rio</a>&#8217;s &quot;one-liners&quot;, but has an
1190
- implication that may be surprising at first. A <a
1191
- href="../Rio.html">Rio</a> starts life as a path, not much more than a
1192
- string. When one of its read methods is called it becomes an input stream.
1193
- When the stream is closed, it becomes a path again. This means that when
1194
- reading from a <a href="../Rio.html">Rio</a>, the end-of-file condition is
1195
- seen only once before it becomes a path again, and will be reopened if
1196
- another read operation is attempted.
1197
- </p>
1198
- <p>
1199
- Another time a <a href="../Rio.html">Rio</a> will be closed atomatically is
1200
- when writing to it with one of the copy operators (<tt>&lt;, &lt;&lt;,
1201
- &gt;, &gt;&gt;</tt>). This behavior can be turned off with <a
1202
- href="../Rio.html#M000072">Rio#nocloseoncopy</a>.
1203
- </p>
1204
- <p>
1205
- To turn off both of thes types of automatic closing use Rio#noautoclose.
1206
- </p>
1207
- <p>
1208
- The third instance when <a href="../Rio.html">Rio</a> will close a file
1209
- automatically is when a file opened for one type of access receives a
1210
- method which that access mode does not support. So, the code
1211
- </p>
1212
- <pre>
1213
- rio('afile').puts(&quot;Hello World&quot;).gets
1214
- </pre>
1215
- <p>
1216
- will open the file for write access when the <tt>puts</tt> method is
1217
- received. When <tt>gets</tt> is called the file is closed and reopened with
1218
- read access.
1219
- </p>
1220
- <h4>Explicit Closing of Files</h4>
1221
- <p>
1222
- <a href="../Rio.html">Rio</a> can not determine when the client is finished
1223
- writing to it, as it does using <tt>eof</tt> on read. It is the
1224
- author&#8217;s understanding that Ruby does not support a mechanism to have
1225
- code run when there are no more references to it &#8212; that finalizers
1226
- are not necessarily run immediatly upon an object&#8217;s reference count
1227
- reaching 0. If this understanding is incorrect, some of <a
1228
- href="../Rio.html">Rio</a>&#8217;s extranious ways of closing a file may be
1229
- rethought.
1230
- </p>
1231
- <p>
1232
- That being said, <a href="../Rio.html">Rio</a> support several ways to
1233
- explicitly close a file. <a href="../Rio.html#M000141">Rio#close</a> will
1234
- close any open <a href="../Rio.html">Rio</a>. The output methods <a
1235
- href="../Rio.html#M000132">Rio#puts</a>!, <a
1236
- href="../Rio.html#M000131">Rio#putc</a>!, <a
1237
- href="../Rio.html#M000129">Rio#printf</a>!, <a
1238
- href="../Rio.html#M000126">Rio#print</a>!, and <a
1239
- href="../Rio.html#M000135">Rio#write</a>! behave as if their counterparts
1240
- without the exclamation point had been called and then call <a
1241
- href="../Rio.html#M000141">Rio#close</a> or Rio#close_write if the
1242
- underlying IO object is opened for duplex access.
1243
- </p>
1244
- <h4>Open mode selection</h4>
1245
- <p>
1246
- A <a href="../Rio.html">Rio</a> is typically not explicitly opened. It
1247
- opens a file automatically when an input or output methed is called. For
1248
- output methods <a href="../Rio.html">Rio</a> opens a file with mode
1249
- &#8216;w&#8217;, and otherwise opens a file with mode &#8216;r&#8217;. This
1250
- behavior can be modified using the tersely named methods <a
1251
- href="../Rio.html#M000062">Rio#a</a>, <a
1252
- href="../Rio.html#M000062">Rio#a</a>!, <a
1253
- href="../Rio.html#M000064">Rio#r</a>, <a
1254
- href="../Rio.html#M000064">Rio#r</a>!, <a
1255
- href="../Rio.html#M000066">Rio#w</a>, and <a
1256
- href="../Rio.html#M000066">Rio#w</a>!, which cause the <a
1257
- href="../Rio.html">Rio</a> to use modes
1258
- &#8216;a&#8217;,&#8217;a+&#8217;,&#8217;r&#8217;,&#8217;r+&#8217;,&#8217;w&#8217;,and
1259
- &#8216;w+&#8217; respectively.
1260
- </p>
1261
- <p>
1262
- One way to append a string to a file and close it in one line is
1263
- </p>
1264
- <pre>
1265
- rio('afile').a.puts!(&quot;Hello World&quot;)
1266
- </pre>
1267
- <p>
1268
- Run a cmd that must be opened for read and write
1269
- </p>
1270
- <pre>
1271
- ans = rio(?-,'cat').w!.puts!(&quot;Hello Kitty&quot;).readlines
1272
- </pre>
1273
- <p>
1274
- The automatic selection of mode can be bypassed entirely using <a
1275
- href="../Rio.html#M000139">Rio#mode</a> and <a
1276
- href="../Rio.html#M000007">Rio#open</a>.
1277
- </p>
1278
- <p>
1279
- If a mode is specified using <tt>mode</tt>, the file will still be opened
1280
- automatically, but the mode specified in the <tt>mode</tt> method will be
1281
- used regardless of whether it makes sense.
1282
- </p>
1283
- <p>
1284
- A <a href="../Rio.html">Rio</a> can also be opened explicitly using <a
1285
- href="../Rio.html#M000007">Rio#open</a>. <tt>open</tt> takes one parameter,
1286
- a mode. This also will override all of <a
1287
- href="../Rio.html">Rio</a>&#8217;s automatic mode selection.
1288
- </p>
1289
- <hr size="1"></hr><p>
1290
- See also:
1291
- </p>
1292
- <ul>
1293
- <li><a href="SYNOPSIS.html">RIO::Doc::SYNOPSIS</a>
1294
-
1295
- </li>
1296
- <li><a href="HOWTO.html">RIO::Doc::HOWTO</a>
1297
-
1298
- </li>
1299
- <li><a href="../Rio.html">RIO::Rio</a>
1300
-
1301
- </li>
1302
- </ul>
1303
-
1304
- </div>
1305
-
1306
-
1307
- </div>
1308
-
1309
-
1310
- </div>
1311
-
1312
-
1313
- <!-- if includes -->
1314
-
1315
- <div id="section">
1316
-
1317
-
1318
-
1319
-
1320
-
1321
-
1322
-
1323
-
1324
- <!-- if method_list -->
1325
-
1326
-
1327
- </div>
1328
-
1329
-
1330
- <div id="validator-badges">
1331
- <p><small>Copyright &copy; 2005 Christopher Kleckner. <a href="http://www.gnu.org/licenses/gpl.html">All rights reserved</a>.</small></p>
1332
- </div>
1333
-
1334
- </body>
1335
- </html>