rbs 4.1.0.pre.2-java

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 (574) hide show
  1. checksums.yaml +7 -0
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.github/dependabot.yml +24 -0
  5. data/.github/workflows/bundle-update.yml +63 -0
  6. data/.github/workflows/c-check.yml +61 -0
  7. data/.github/workflows/comments.yml +37 -0
  8. data/.github/workflows/dependabot.yml +30 -0
  9. data/.github/workflows/jruby.yml +67 -0
  10. data/.github/workflows/milestone.yml +83 -0
  11. data/.github/workflows/ruby.yml +158 -0
  12. data/.github/workflows/rust.yml +184 -0
  13. data/.github/workflows/truffleruby.yml +54 -0
  14. data/.github/workflows/typecheck.yml +39 -0
  15. data/.github/workflows/wasm.yml +53 -0
  16. data/.github/workflows/windows.yml +49 -0
  17. data/.gitignore +38 -0
  18. data/.rubocop.yml +72 -0
  19. data/BSDL +22 -0
  20. data/CHANGELOG.md +2292 -0
  21. data/COPYING +56 -0
  22. data/README.md +240 -0
  23. data/Rakefile +869 -0
  24. data/Steepfile +53 -0
  25. data/config.yml +913 -0
  26. data/core/array.rbs +4142 -0
  27. data/core/basic_object.rbs +376 -0
  28. data/core/binding.rbs +148 -0
  29. data/core/builtin.rbs +278 -0
  30. data/core/class.rbs +223 -0
  31. data/core/comparable.rbs +192 -0
  32. data/core/complex.rbs +812 -0
  33. data/core/constants.rbs +96 -0
  34. data/core/data.rbs +415 -0
  35. data/core/dir.rbs +993 -0
  36. data/core/encoding.rbs +1368 -0
  37. data/core/enumerable.rbs +2506 -0
  38. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  39. data/core/enumerator/product.rbs +92 -0
  40. data/core/enumerator.rbs +705 -0
  41. data/core/env.rbs +6 -0
  42. data/core/errno.rbs +682 -0
  43. data/core/errors.rbs +789 -0
  44. data/core/exception.rbs +485 -0
  45. data/core/false_class.rbs +82 -0
  46. data/core/fiber.rbs +570 -0
  47. data/core/fiber_error.rbs +11 -0
  48. data/core/file.rbs +2045 -0
  49. data/core/file_constants.rbs +463 -0
  50. data/core/file_stat.rbs +534 -0
  51. data/core/file_test.rbs +331 -0
  52. data/core/float.rbs +1316 -0
  53. data/core/gc.rbs +788 -0
  54. data/core/global_variables.rbs +184 -0
  55. data/core/hash.rbs +2183 -0
  56. data/core/integer.rbs +1374 -0
  57. data/core/io/buffer.rbs +995 -0
  58. data/core/io/wait.rbs +48 -0
  59. data/core/io.rbs +3472 -0
  60. data/core/kernel.rbs +3172 -0
  61. data/core/marshal.rbs +207 -0
  62. data/core/match_data.rbs +637 -0
  63. data/core/math.rbs +770 -0
  64. data/core/method.rbs +422 -0
  65. data/core/module.rbs +1856 -0
  66. data/core/nil_class.rbs +210 -0
  67. data/core/numeric.rbs +832 -0
  68. data/core/object.rbs +108 -0
  69. data/core/object_space/weak_key_map.rbs +166 -0
  70. data/core/object_space.rbs +197 -0
  71. data/core/pathname.rbs +1322 -0
  72. data/core/proc.rbs +905 -0
  73. data/core/process.rbs +2316 -0
  74. data/core/ractor.rbs +924 -0
  75. data/core/random.rbs +255 -0
  76. data/core/range.rbs +1209 -0
  77. data/core/rational.rbs +502 -0
  78. data/core/rb_config.rbs +88 -0
  79. data/core/rbs/ops.rbs +154 -0
  80. data/core/rbs/unnamed/argf.rbs +1236 -0
  81. data/core/rbs/unnamed/env_class.rbs +1214 -0
  82. data/core/rbs/unnamed/main_class.rbs +123 -0
  83. data/core/rbs/unnamed/random.rbs +186 -0
  84. data/core/refinement.rbs +59 -0
  85. data/core/regexp.rbs +1974 -0
  86. data/core/ruby.rbs +53 -0
  87. data/core/ruby_vm.rbs +809 -0
  88. data/core/rubygems/basic_specification.rbs +6 -0
  89. data/core/rubygems/config_file.rbs +38 -0
  90. data/core/rubygems/dependency_installer.rbs +6 -0
  91. data/core/rubygems/errors.rbs +109 -0
  92. data/core/rubygems/installer.rbs +15 -0
  93. data/core/rubygems/path_support.rbs +6 -0
  94. data/core/rubygems/platform.rbs +7 -0
  95. data/core/rubygems/request_set.rbs +49 -0
  96. data/core/rubygems/requirement.rbs +148 -0
  97. data/core/rubygems/rubygems.rbs +1105 -0
  98. data/core/rubygems/source_list.rbs +15 -0
  99. data/core/rubygems/specification.rbs +23 -0
  100. data/core/rubygems/stream_ui.rbs +5 -0
  101. data/core/rubygems/uninstaller.rbs +10 -0
  102. data/core/rubygems/version.rbs +293 -0
  103. data/core/set.rbs +751 -0
  104. data/core/signal.rbs +110 -0
  105. data/core/string.rbs +5532 -0
  106. data/core/struct.rbs +668 -0
  107. data/core/symbol.rbs +482 -0
  108. data/core/thread.rbs +1826 -0
  109. data/core/thread_group.rbs +79 -0
  110. data/core/time.rbs +1793 -0
  111. data/core/trace_point.rbs +483 -0
  112. data/core/true_class.rbs +98 -0
  113. data/core/unbound_method.rbs +337 -0
  114. data/core/warning.rbs +87 -0
  115. data/docs/CONTRIBUTING.md +107 -0
  116. data/docs/aliases.md +79 -0
  117. data/docs/architecture.md +110 -0
  118. data/docs/collection.md +192 -0
  119. data/docs/config.md +171 -0
  120. data/docs/data_and_struct.md +86 -0
  121. data/docs/encoding.md +56 -0
  122. data/docs/gem.md +56 -0
  123. data/docs/inline.md +634 -0
  124. data/docs/rbs_by_example.md +309 -0
  125. data/docs/repo.md +125 -0
  126. data/docs/rust.md +96 -0
  127. data/docs/sigs.md +167 -0
  128. data/docs/stdlib.md +147 -0
  129. data/docs/syntax.md +940 -0
  130. data/docs/tools.md +17 -0
  131. data/docs/type_fingerprint.md +21 -0
  132. data/docs/wasm_serialization.md +80 -0
  133. data/exe/rbs +7 -0
  134. data/ext/rbs_extension/ast_translation.c +1855 -0
  135. data/ext/rbs_extension/ast_translation.h +41 -0
  136. data/ext/rbs_extension/class_constants.c +187 -0
  137. data/ext/rbs_extension/class_constants.h +104 -0
  138. data/ext/rbs_extension/compat.h +10 -0
  139. data/ext/rbs_extension/extconf.rb +40 -0
  140. data/ext/rbs_extension/legacy_location.c +294 -0
  141. data/ext/rbs_extension/legacy_location.h +82 -0
  142. data/ext/rbs_extension/main.c +613 -0
  143. data/ext/rbs_extension/rbs_extension.h +16 -0
  144. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  145. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  146. data/goodcheck.yml +91 -0
  147. data/include/rbs/ast.h +1047 -0
  148. data/include/rbs/defines.h +99 -0
  149. data/include/rbs/lexer.h +207 -0
  150. data/include/rbs/location.h +40 -0
  151. data/include/rbs/parser.h +153 -0
  152. data/include/rbs/serialize.h +39 -0
  153. data/include/rbs/string.h +47 -0
  154. data/include/rbs/util/rbs_allocator.h +59 -0
  155. data/include/rbs/util/rbs_assert.h +20 -0
  156. data/include/rbs/util/rbs_buffer.h +83 -0
  157. data/include/rbs/util/rbs_constant_pool.h +155 -0
  158. data/include/rbs/util/rbs_encoding.h +282 -0
  159. data/include/rbs/util/rbs_unescape.h +24 -0
  160. data/include/rbs.h +14 -0
  161. data/lib/rbs/ancestor_graph.rb +92 -0
  162. data/lib/rbs/annotate/annotations.rb +199 -0
  163. data/lib/rbs/annotate/formatter.rb +82 -0
  164. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  165. data/lib/rbs/annotate/rdoc_source.rb +131 -0
  166. data/lib/rbs/annotate.rb +8 -0
  167. data/lib/rbs/ast/annotation.rb +29 -0
  168. data/lib/rbs/ast/comment.rb +29 -0
  169. data/lib/rbs/ast/declarations.rb +472 -0
  170. data/lib/rbs/ast/directives.rb +49 -0
  171. data/lib/rbs/ast/members.rb +451 -0
  172. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  173. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  174. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  175. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  176. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  177. data/lib/rbs/ast/ruby/members.rb +762 -0
  178. data/lib/rbs/ast/type_param.rb +235 -0
  179. data/lib/rbs/ast/visitor.rb +137 -0
  180. data/lib/rbs/buffer.rb +189 -0
  181. data/lib/rbs/builtin_names.rb +58 -0
  182. data/lib/rbs/cli/colored_io.rb +48 -0
  183. data/lib/rbs/cli/diff.rb +84 -0
  184. data/lib/rbs/cli/validate.rb +294 -0
  185. data/lib/rbs/cli.rb +1253 -0
  186. data/lib/rbs/collection/cleaner.rb +38 -0
  187. data/lib/rbs/collection/config/lockfile.rb +92 -0
  188. data/lib/rbs/collection/config/lockfile_generator.rb +269 -0
  189. data/lib/rbs/collection/config.rb +81 -0
  190. data/lib/rbs/collection/installer.rb +32 -0
  191. data/lib/rbs/collection/sources/base.rb +14 -0
  192. data/lib/rbs/collection/sources/git.rb +265 -0
  193. data/lib/rbs/collection/sources/local.rb +81 -0
  194. data/lib/rbs/collection/sources/rubygems.rb +48 -0
  195. data/lib/rbs/collection/sources/stdlib.rb +50 -0
  196. data/lib/rbs/collection/sources.rb +38 -0
  197. data/lib/rbs/collection.rb +16 -0
  198. data/lib/rbs/constant.rb +28 -0
  199. data/lib/rbs/definition.rb +415 -0
  200. data/lib/rbs/definition_builder/ancestor_builder.rb +678 -0
  201. data/lib/rbs/definition_builder/method_builder.rb +295 -0
  202. data/lib/rbs/definition_builder.rb +1054 -0
  203. data/lib/rbs/diff.rb +131 -0
  204. data/lib/rbs/environment/class_entry.rb +69 -0
  205. data/lib/rbs/environment/module_entry.rb +66 -0
  206. data/lib/rbs/environment/use_map.rb +77 -0
  207. data/lib/rbs/environment.rb +1028 -0
  208. data/lib/rbs/environment_loader.rb +167 -0
  209. data/lib/rbs/environment_walker.rb +155 -0
  210. data/lib/rbs/errors.rb +634 -0
  211. data/lib/rbs/factory.rb +18 -0
  212. data/lib/rbs/file_finder.rb +28 -0
  213. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  214. data/lib/rbs/inline_parser.rb +568 -0
  215. data/lib/rbs/location_aux.rb +170 -0
  216. data/lib/rbs/locator.rb +247 -0
  217. data/lib/rbs/method_type.rb +145 -0
  218. data/lib/rbs/namespace.rb +154 -0
  219. data/lib/rbs/parser/lex_result.rb +15 -0
  220. data/lib/rbs/parser/token.rb +23 -0
  221. data/lib/rbs/parser_aux.rb +142 -0
  222. data/lib/rbs/prototype/helpers.rb +197 -0
  223. data/lib/rbs/prototype/node_usage.rb +99 -0
  224. data/lib/rbs/prototype/rb.rb +816 -0
  225. data/lib/rbs/prototype/rbi.rb +625 -0
  226. data/lib/rbs/prototype/runtime/helpers.rb +59 -0
  227. data/lib/rbs/prototype/runtime/reflection.rb +19 -0
  228. data/lib/rbs/prototype/runtime/value_object_generator.rb +279 -0
  229. data/lib/rbs/prototype/runtime.rb +680 -0
  230. data/lib/rbs/repository.rb +127 -0
  231. data/lib/rbs/resolver/constant_resolver.rb +219 -0
  232. data/lib/rbs/resolver/type_name_resolver.rb +167 -0
  233. data/lib/rbs/rewriter.rb +70 -0
  234. data/lib/rbs/sorter.rb +198 -0
  235. data/lib/rbs/source.rb +99 -0
  236. data/lib/rbs/substitution.rb +83 -0
  237. data/lib/rbs/subtractor.rb +204 -0
  238. data/lib/rbs/test/errors.rb +80 -0
  239. data/lib/rbs/test/guaranteed.rb +30 -0
  240. data/lib/rbs/test/hook.rb +212 -0
  241. data/lib/rbs/test/observer.rb +19 -0
  242. data/lib/rbs/test/setup.rb +84 -0
  243. data/lib/rbs/test/setup_helper.rb +50 -0
  244. data/lib/rbs/test/tester.rb +167 -0
  245. data/lib/rbs/test/type_check.rb +457 -0
  246. data/lib/rbs/test.rb +112 -0
  247. data/lib/rbs/type_alias_dependency.rb +100 -0
  248. data/lib/rbs/type_alias_regularity.rb +126 -0
  249. data/lib/rbs/type_name.rb +122 -0
  250. data/lib/rbs/types.rb +1604 -0
  251. data/lib/rbs/unit_test/convertibles.rb +177 -0
  252. data/lib/rbs/unit_test/spy.rb +138 -0
  253. data/lib/rbs/unit_test/type_assertions.rb +383 -0
  254. data/lib/rbs/unit_test/with_aliases.rb +145 -0
  255. data/lib/rbs/unit_test.rb +6 -0
  256. data/lib/rbs/validator.rb +186 -0
  257. data/lib/rbs/variance_calculator.rb +189 -0
  258. data/lib/rbs/vendorer.rb +71 -0
  259. data/lib/rbs/version.rb +5 -0
  260. data/lib/rbs/wasm/deserializer.rb +213 -0
  261. data/lib/rbs/wasm/jars/asm-analysis.jar +0 -0
  262. data/lib/rbs/wasm/jars/asm-commons.jar +0 -0
  263. data/lib/rbs/wasm/jars/asm-tree.jar +0 -0
  264. data/lib/rbs/wasm/jars/asm-util.jar +0 -0
  265. data/lib/rbs/wasm/jars/asm.jar +0 -0
  266. data/lib/rbs/wasm/jars/compiler.jar +0 -0
  267. data/lib/rbs/wasm/jars/log.jar +0 -0
  268. data/lib/rbs/wasm/jars/runtime.jar +0 -0
  269. data/lib/rbs/wasm/jars/wasi.jar +0 -0
  270. data/lib/rbs/wasm/jars/wasm.jar +0 -0
  271. data/lib/rbs/wasm/location.rb +61 -0
  272. data/lib/rbs/wasm/parser.rb +137 -0
  273. data/lib/rbs/wasm/rbs_parser.wasm +0 -0
  274. data/lib/rbs/wasm/runtime.rb +217 -0
  275. data/lib/rbs/wasm/serialization_schema.rb +110 -0
  276. data/lib/rbs/writer.rb +424 -0
  277. data/lib/rbs.rb +117 -0
  278. data/lib/rdoc/discover.rb +20 -0
  279. data/lib/rdoc_plugin/parser.rb +163 -0
  280. data/rbs.gemspec +68 -0
  281. data/schema/annotation.json +14 -0
  282. data/schema/comment.json +26 -0
  283. data/schema/decls.json +326 -0
  284. data/schema/function.json +87 -0
  285. data/schema/location.json +56 -0
  286. data/schema/members.json +266 -0
  287. data/schema/methodType.json +50 -0
  288. data/schema/typeParam.json +52 -0
  289. data/schema/types.json +317 -0
  290. data/sig/ancestor_builder.rbs +163 -0
  291. data/sig/ancestor_graph.rbs +60 -0
  292. data/sig/annotate/annotations.rbs +102 -0
  293. data/sig/annotate/formatter.rbs +24 -0
  294. data/sig/annotate/rdoc_annotater.rbs +85 -0
  295. data/sig/annotate/rdoc_source.rbs +32 -0
  296. data/sig/annotation.rbs +27 -0
  297. data/sig/ast/ruby/annotations.rbs +470 -0
  298. data/sig/ast/ruby/comment_block.rbs +127 -0
  299. data/sig/ast/ruby/declarations.rbs +158 -0
  300. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  301. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  302. data/sig/ast/ruby/members.rbs +198 -0
  303. data/sig/buffer.rbs +108 -0
  304. data/sig/builtin_names.rbs +44 -0
  305. data/sig/cli/colored_io.rbs +15 -0
  306. data/sig/cli/diff.rbs +15 -0
  307. data/sig/cli/validate.rbs +47 -0
  308. data/sig/cli.rbs +89 -0
  309. data/sig/collection/cleaner.rbs +13 -0
  310. data/sig/collection/config/lockfile.rbs +74 -0
  311. data/sig/collection/config/lockfile_generator.rbs +68 -0
  312. data/sig/collection/config.rbs +46 -0
  313. data/sig/collection/installer.rbs +17 -0
  314. data/sig/collection/sources.rbs +214 -0
  315. data/sig/collection.rbs +4 -0
  316. data/sig/comment.rbs +26 -0
  317. data/sig/constant.rbs +21 -0
  318. data/sig/declarations.rbs +274 -0
  319. data/sig/definition.rbs +232 -0
  320. data/sig/definition_builder.rbs +181 -0
  321. data/sig/diff.rbs +28 -0
  322. data/sig/directives.rbs +77 -0
  323. data/sig/environment/class_entry.rbs +50 -0
  324. data/sig/environment/module_entry.rbs +50 -0
  325. data/sig/environment.rbs +286 -0
  326. data/sig/environment_loader.rbs +111 -0
  327. data/sig/environment_walker.rbs +65 -0
  328. data/sig/errors.rbs +408 -0
  329. data/sig/factory.rbs +5 -0
  330. data/sig/file_finder.rbs +28 -0
  331. data/sig/inline_parser/comment_association.rbs +71 -0
  332. data/sig/inline_parser.rbs +126 -0
  333. data/sig/location.rbs +135 -0
  334. data/sig/locator.rbs +56 -0
  335. data/sig/manifest.yaml +5 -0
  336. data/sig/members.rbs +258 -0
  337. data/sig/method_builder.rbs +89 -0
  338. data/sig/method_types.rbs +58 -0
  339. data/sig/namespace.rbs +161 -0
  340. data/sig/parser.rbs +164 -0
  341. data/sig/prototype/helpers.rbs +29 -0
  342. data/sig/prototype/node_usage.rbs +20 -0
  343. data/sig/prototype/rb.rbs +96 -0
  344. data/sig/prototype/rbi.rbs +75 -0
  345. data/sig/prototype/runtime.rbs +182 -0
  346. data/sig/rbs.rbs +21 -0
  347. data/sig/rdoc/rbs.rbs +67 -0
  348. data/sig/repository.rbs +85 -0
  349. data/sig/resolver/constant_resolver.rbs +92 -0
  350. data/sig/resolver/context.rbs +34 -0
  351. data/sig/resolver/type_name_resolver.rbs +61 -0
  352. data/sig/rewriter.rbs +45 -0
  353. data/sig/shims/bundler.rbs +38 -0
  354. data/sig/shims/enumerable.rbs +5 -0
  355. data/sig/shims/rubygems.rbs +19 -0
  356. data/sig/sorter.rbs +41 -0
  357. data/sig/source.rbs +48 -0
  358. data/sig/substitution.rbs +48 -0
  359. data/sig/subtractor.rbs +37 -0
  360. data/sig/test/errors.rbs +52 -0
  361. data/sig/test/guranteed.rbs +9 -0
  362. data/sig/test/type_check.rbs +19 -0
  363. data/sig/test.rbs +82 -0
  364. data/sig/type_alias_dependency.rbs +53 -0
  365. data/sig/type_alias_regularity.rbs +98 -0
  366. data/sig/type_param.rbs +115 -0
  367. data/sig/typename.rbs +89 -0
  368. data/sig/types.rbs +578 -0
  369. data/sig/unit_test/convertibles.rbs +154 -0
  370. data/sig/unit_test/spy.rbs +22 -0
  371. data/sig/unit_test/type_assertions.rbs +211 -0
  372. data/sig/unit_test/with_aliases.rbs +136 -0
  373. data/sig/use_map.rbs +35 -0
  374. data/sig/util.rbs +9 -0
  375. data/sig/validator.rbs +63 -0
  376. data/sig/variance_calculator.rbs +87 -0
  377. data/sig/vendorer.rbs +51 -0
  378. data/sig/version.rbs +3 -0
  379. data/sig/visitor.rbs +47 -0
  380. data/sig/wasm/deserializer.rbs +66 -0
  381. data/sig/wasm/serialization_schema.rbs +13 -0
  382. data/sig/writer.rbs +127 -0
  383. data/src/ast.c +1628 -0
  384. data/src/lexer.c +3217 -0
  385. data/src/lexer.re +155 -0
  386. data/src/lexstate.c +217 -0
  387. data/src/location.c +31 -0
  388. data/src/parser.c +4255 -0
  389. data/src/serialize.c +958 -0
  390. data/src/string.c +41 -0
  391. data/src/util/rbs_allocator.c +162 -0
  392. data/src/util/rbs_assert.c +19 -0
  393. data/src/util/rbs_buffer.c +54 -0
  394. data/src/util/rbs_constant_pool.c +268 -0
  395. data/src/util/rbs_encoding.c +21308 -0
  396. data/src/util/rbs_unescape.c +167 -0
  397. data/stdlib/abbrev/0/abbrev.rbs +66 -0
  398. data/stdlib/abbrev/0/array.rbs +26 -0
  399. data/stdlib/base64/0/base64.rbs +355 -0
  400. data/stdlib/benchmark/0/benchmark.rbs +452 -0
  401. data/stdlib/bigdecimal/0/big_decimal.rbs +1647 -0
  402. data/stdlib/bigdecimal-math/0/big_math.rbs +280 -0
  403. data/stdlib/bigdecimal-math/0/manifest.yaml +2 -0
  404. data/stdlib/cgi/0/core.rbs +911 -0
  405. data/stdlib/cgi/0/manifest.yaml +4 -0
  406. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  407. data/stdlib/coverage/0/coverage.rbs +266 -0
  408. data/stdlib/csv/0/csv.rbs +3776 -0
  409. data/stdlib/csv/0/manifest.yaml +3 -0
  410. data/stdlib/date/0/date.rbs +1598 -0
  411. data/stdlib/date/0/date_time.rbs +617 -0
  412. data/stdlib/date/0/time.rbs +26 -0
  413. data/stdlib/dbm/0/dbm.rbs +421 -0
  414. data/stdlib/delegate/0/delegator.rbs +187 -0
  415. data/stdlib/delegate/0/kernel.rbs +47 -0
  416. data/stdlib/delegate/0/simple_delegator.rbs +96 -0
  417. data/stdlib/did_you_mean/0/did_you_mean.rbs +344 -0
  418. data/stdlib/digest/0/digest.rbs +687 -0
  419. data/stdlib/erb/0/erb.rbs +933 -0
  420. data/stdlib/etc/0/etc.rbs +884 -0
  421. data/stdlib/fileutils/0/fileutils.rbs +1753 -0
  422. data/stdlib/find/0/find.rbs +49 -0
  423. data/stdlib/forwardable/0/forwardable.rbs +271 -0
  424. data/stdlib/io-console/0/io-console.rbs +414 -0
  425. data/stdlib/ipaddr/0/ipaddr.rbs +436 -0
  426. data/stdlib/json/0/json.rbs +1963 -0
  427. data/stdlib/kconv/0/kconv.rbs +166 -0
  428. data/stdlib/logger/0/formatter.rbs +45 -0
  429. data/stdlib/logger/0/log_device.rbs +100 -0
  430. data/stdlib/logger/0/logger.rbs +796 -0
  431. data/stdlib/logger/0/manifest.yaml +2 -0
  432. data/stdlib/logger/0/period.rbs +17 -0
  433. data/stdlib/logger/0/severity.rbs +34 -0
  434. data/stdlib/minitest/0/kernel.rbs +42 -0
  435. data/stdlib/minitest/0/minitest/abstract_reporter.rbs +52 -0
  436. data/stdlib/minitest/0/minitest/assertion.rbs +17 -0
  437. data/stdlib/minitest/0/minitest/assertions.rbs +590 -0
  438. data/stdlib/minitest/0/minitest/backtrace_filter.rbs +23 -0
  439. data/stdlib/minitest/0/minitest/bench_spec.rbs +102 -0
  440. data/stdlib/minitest/0/minitest/benchmark.rbs +259 -0
  441. data/stdlib/minitest/0/minitest/composite_reporter.rbs +25 -0
  442. data/stdlib/minitest/0/minitest/compress.rbs +13 -0
  443. data/stdlib/minitest/0/minitest/error_on_warning.rbs +3 -0
  444. data/stdlib/minitest/0/minitest/expectation.rbs +2 -0
  445. data/stdlib/minitest/0/minitest/expectations.rbs +21 -0
  446. data/stdlib/minitest/0/minitest/guard.rbs +64 -0
  447. data/stdlib/minitest/0/minitest/mock.rbs +64 -0
  448. data/stdlib/minitest/0/minitest/parallel/executor.rbs +46 -0
  449. data/stdlib/minitest/0/minitest/parallel/test/class_methods.rbs +5 -0
  450. data/stdlib/minitest/0/minitest/parallel/test.rbs +3 -0
  451. data/stdlib/minitest/0/minitest/parallel.rbs +2 -0
  452. data/stdlib/minitest/0/minitest/pride_io.rbs +62 -0
  453. data/stdlib/minitest/0/minitest/pride_lol.rbs +19 -0
  454. data/stdlib/minitest/0/minitest/progress_reporter.rbs +11 -0
  455. data/stdlib/minitest/0/minitest/reportable.rbs +53 -0
  456. data/stdlib/minitest/0/minitest/reporter.rbs +5 -0
  457. data/stdlib/minitest/0/minitest/result.rbs +28 -0
  458. data/stdlib/minitest/0/minitest/runnable.rbs +163 -0
  459. data/stdlib/minitest/0/minitest/skip.rbs +6 -0
  460. data/stdlib/minitest/0/minitest/spec/dsl/instance_methods.rbs +48 -0
  461. data/stdlib/minitest/0/minitest/spec/dsl.rbs +129 -0
  462. data/stdlib/minitest/0/minitest/spec.rbs +11 -0
  463. data/stdlib/minitest/0/minitest/statistics_reporter.rbs +81 -0
  464. data/stdlib/minitest/0/minitest/summary_reporter.rbs +18 -0
  465. data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +92 -0
  466. data/stdlib/minitest/0/minitest/test.rbs +69 -0
  467. data/stdlib/minitest/0/minitest/unexpected_error.rbs +12 -0
  468. data/stdlib/minitest/0/minitest/unexpected_warning.rbs +6 -0
  469. data/stdlib/minitest/0/minitest/unit/test_case.rbs +3 -0
  470. data/stdlib/minitest/0/minitest/unit.rbs +4 -0
  471. data/stdlib/minitest/0/minitest.rbs +115 -0
  472. data/stdlib/monitor/0/monitor.rbs +363 -0
  473. data/stdlib/mutex_m/0/mutex_m.rbs +104 -0
  474. data/stdlib/net-http/0/manifest.yaml +3 -0
  475. data/stdlib/net-http/0/net-http.rbs +5580 -0
  476. data/stdlib/net-protocol/0/manifest.yaml +2 -0
  477. data/stdlib/net-protocol/0/net-protocol.rbs +56 -0
  478. data/stdlib/net-smtp/0/manifest.yaml +2 -0
  479. data/stdlib/net-smtp/0/net-smtp.rbs +55 -0
  480. data/stdlib/nkf/0/nkf.rbs +402 -0
  481. data/stdlib/objspace/0/objspace.rbs +470 -0
  482. data/stdlib/observable/0/observable.rbs +217 -0
  483. data/stdlib/open-uri/0/manifest.yaml +4 -0
  484. data/stdlib/open-uri/0/open-uri.rbs +433 -0
  485. data/stdlib/open3/0/open3.rbs +606 -0
  486. data/stdlib/openssl/0/manifest.yaml +3 -0
  487. data/stdlib/openssl/0/openssl.rbs +12231 -0
  488. data/stdlib/optparse/0/optparse.rbs +1734 -0
  489. data/stdlib/pathname/0/pathname.rbs +36 -0
  490. data/stdlib/pp/0/manifest.yaml +2 -0
  491. data/stdlib/pp/0/pp.rbs +301 -0
  492. data/stdlib/prettyprint/0/prettyprint.rbs +383 -0
  493. data/stdlib/pstore/0/pstore.rbs +608 -0
  494. data/stdlib/psych/0/core_ext.rbs +12 -0
  495. data/stdlib/psych/0/dbm.rbs +237 -0
  496. data/stdlib/psych/0/manifest.yaml +3 -0
  497. data/stdlib/psych/0/psych.rbs +455 -0
  498. data/stdlib/psych/0/store.rbs +57 -0
  499. data/stdlib/pty/0/pty.rbs +240 -0
  500. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  501. data/stdlib/rdoc/0/code_object.rbs +52 -0
  502. data/stdlib/rdoc/0/comment.rbs +61 -0
  503. data/stdlib/rdoc/0/context.rbs +153 -0
  504. data/stdlib/rdoc/0/markup.rbs +117 -0
  505. data/stdlib/rdoc/0/options.rbs +76 -0
  506. data/stdlib/rdoc/0/parser.rbs +56 -0
  507. data/stdlib/rdoc/0/rdoc.rbs +393 -0
  508. data/stdlib/rdoc/0/ri.rbs +17 -0
  509. data/stdlib/rdoc/0/store.rbs +48 -0
  510. data/stdlib/rdoc/0/top_level.rbs +97 -0
  511. data/stdlib/resolv/0/manifest.yaml +3 -0
  512. data/stdlib/resolv/0/resolv.rbs +1787 -0
  513. data/stdlib/ripper/0/ripper.rbs +1654 -0
  514. data/stdlib/securerandom/0/manifest.yaml +2 -0
  515. data/stdlib/securerandom/0/securerandom.rbs +49 -0
  516. data/stdlib/shellwords/0/shellwords.rbs +229 -0
  517. data/stdlib/singleton/0/singleton.rbs +134 -0
  518. data/stdlib/socket/0/addrinfo.rbs +666 -0
  519. data/stdlib/socket/0/basic_socket.rbs +590 -0
  520. data/stdlib/socket/0/constants.rbs +2295 -0
  521. data/stdlib/socket/0/ip_socket.rbs +94 -0
  522. data/stdlib/socket/0/socket.rbs +4170 -0
  523. data/stdlib/socket/0/socket_error.rbs +5 -0
  524. data/stdlib/socket/0/tcp_server.rbs +192 -0
  525. data/stdlib/socket/0/tcp_socket.rbs +87 -0
  526. data/stdlib/socket/0/udp_socket.rbs +133 -0
  527. data/stdlib/socket/0/unix_server.rbs +169 -0
  528. data/stdlib/socket/0/unix_socket.rbs +172 -0
  529. data/stdlib/stringio/0/stringio.rbs +1681 -0
  530. data/stdlib/strscan/0/string_scanner.rbs +1648 -0
  531. data/stdlib/tempfile/0/tempfile.rbs +483 -0
  532. data/stdlib/time/0/time.rbs +434 -0
  533. data/stdlib/timeout/0/timeout.rbs +137 -0
  534. data/stdlib/tmpdir/0/tmpdir.rbs +69 -0
  535. data/stdlib/tsort/0/cyclic.rbs +8 -0
  536. data/stdlib/tsort/0/interfaces.rbs +20 -0
  537. data/stdlib/tsort/0/tsort.rbs +410 -0
  538. data/stdlib/uri/0/common.rbs +621 -0
  539. data/stdlib/uri/0/file.rbs +118 -0
  540. data/stdlib/uri/0/ftp.rbs +13 -0
  541. data/stdlib/uri/0/generic.rbs +1116 -0
  542. data/stdlib/uri/0/http.rbs +104 -0
  543. data/stdlib/uri/0/https.rbs +14 -0
  544. data/stdlib/uri/0/ldap.rbs +230 -0
  545. data/stdlib/uri/0/ldaps.rbs +14 -0
  546. data/stdlib/uri/0/mailto.rbs +92 -0
  547. data/stdlib/uri/0/rfc2396_parser.rbs +189 -0
  548. data/stdlib/uri/0/rfc3986_parser.rbs +2 -0
  549. data/stdlib/uri/0/ws.rbs +13 -0
  550. data/stdlib/uri/0/wss.rbs +9 -0
  551. data/stdlib/yaml/0/manifest.yaml +2 -0
  552. data/stdlib/yaml/0/yaml.rbs +1 -0
  553. data/stdlib/zlib/0/buf_error.rbs +10 -0
  554. data/stdlib/zlib/0/data_error.rbs +10 -0
  555. data/stdlib/zlib/0/deflate.rbs +211 -0
  556. data/stdlib/zlib/0/error.rbs +20 -0
  557. data/stdlib/zlib/0/gzip_file/crc_error.rbs +12 -0
  558. data/stdlib/zlib/0/gzip_file/error.rbs +23 -0
  559. data/stdlib/zlib/0/gzip_file/length_error.rbs +12 -0
  560. data/stdlib/zlib/0/gzip_file/no_footer.rbs +11 -0
  561. data/stdlib/zlib/0/gzip_file.rbs +156 -0
  562. data/stdlib/zlib/0/gzip_reader.rbs +293 -0
  563. data/stdlib/zlib/0/gzip_writer.rbs +168 -0
  564. data/stdlib/zlib/0/inflate.rbs +180 -0
  565. data/stdlib/zlib/0/mem_error.rbs +10 -0
  566. data/stdlib/zlib/0/need_dict.rbs +13 -0
  567. data/stdlib/zlib/0/stream_end.rbs +11 -0
  568. data/stdlib/zlib/0/stream_error.rbs +11 -0
  569. data/stdlib/zlib/0/version_error.rbs +11 -0
  570. data/stdlib/zlib/0/zlib.rbs +449 -0
  571. data/stdlib/zlib/0/zstream.rbs +201 -0
  572. data/wasm/README.md +59 -0
  573. data/wasm/rbs_wasm.c +411 -0
  574. metadata +660 -0
data/core/io.rbs ADDED
@@ -0,0 +1,3472 @@
1
+ # <!-- rdoc-file=io.c -->
2
+ # An instance of class IO (commonly called a *stream*) represents an
3
+ # input/output stream in the underlying operating system. Class IO is the basis
4
+ # for input and output in Ruby.
5
+ #
6
+ # Class File is the only class in the Ruby core that is a subclass of IO. Some
7
+ # classes in the Ruby standard library are also subclasses of IO; these include
8
+ # TCPSocket and UDPSocket.
9
+ #
10
+ # The global constant ARGF (also accessible as <code>$<</code>) provides an
11
+ # IO-like stream that allows access to all file paths found in ARGV (or found in
12
+ # STDIN if ARGV is empty). ARGF is not itself a subclass of IO.
13
+ #
14
+ # Class StringIO provides an IO-like stream that handles a String. StringIO is
15
+ # not itself a subclass of IO.
16
+ #
17
+ # Important objects based on IO include:
18
+ #
19
+ # * $stdin.
20
+ # * $stdout.
21
+ # * $stderr.
22
+ # * Instances of class File.
23
+ #
24
+ # An instance of IO may be created using:
25
+ #
26
+ # * IO.new: returns a new IO object for the given integer file descriptor.
27
+ # * IO.open: passes a new IO object to the given block.
28
+ # * IO.popen: returns a new IO object that is connected to the $stdin and
29
+ # $stdout of a newly-launched subprocess.
30
+ # * Kernel#open: Returns a new IO object connected to a given source: stream,
31
+ # file, or subprocess.
32
+ #
33
+ # Like a File stream, an IO stream has:
34
+ #
35
+ # * A read/write mode, which may be read-only, write-only, or read/write; see
36
+ # [Read/Write Mode](rdoc-ref:File@Read-2FWrite+Mode).
37
+ # * A data mode, which may be text-only or binary; see [Data
38
+ # Mode](rdoc-ref:File@Data+Mode).
39
+ # * Internal and external encodings; see [Encodings](rdoc-ref:File@Encodings).
40
+ #
41
+ # And like other IO streams, it has:
42
+ #
43
+ # * A position, which determines where in the stream the next read or write is
44
+ # to occur; see [Position](rdoc-ref:IO@Position).
45
+ # * A line number, which is a special, line-oriented, "position" (different
46
+ # from the position mentioned above); see [Line
47
+ # Number](rdoc-ref:IO@Line+Number).
48
+ #
49
+ # ## Extension <code>io/console</code>
50
+ #
51
+ # Extension <code>io/console</code> provides numerous methods for interacting
52
+ # with the console; requiring it adds numerous methods to class IO.
53
+ #
54
+ # ## Example Files
55
+ #
56
+ # Many examples here use these variables:
57
+ #
58
+ # # English text with newlines.
59
+ # text = <<~EOT
60
+ # First line
61
+ # Second line
62
+ #
63
+ # Fourth line
64
+ # Fifth line
65
+ # EOT
66
+ #
67
+ # # Russian text.
68
+ # russian = "\u{442 435 441 442}" # => "тест"
69
+ #
70
+ # # Binary data.
71
+ # data = "\u9990\u9991\u9992\u9993\u9994"
72
+ #
73
+ # # Text file.
74
+ # File.write('t.txt', text)
75
+ #
76
+ # # File with Russian text.
77
+ # File.write('t.rus', russian)
78
+ #
79
+ # # File with binary data.
80
+ # f = File.new('t.dat', 'wb:UTF-16')
81
+ # f.write(data)
82
+ # f.close
83
+ #
84
+ # ## Open Options
85
+ #
86
+ # A number of IO methods accept optional keyword arguments that determine how a
87
+ # new stream is to be opened:
88
+ #
89
+ # * <code>:mode</code>: Stream mode.
90
+ # * <code>:flags</code>: Integer file open flags; If `mode` is also given, the
91
+ # two are bitwise-ORed.
92
+ # * <code>:external_encoding</code>: External encoding for the stream.
93
+ # * <code>:internal_encoding</code>: Internal encoding for the stream.
94
+ # <code>'-'</code> is a synonym for the default internal encoding. If the
95
+ # value is `nil` no conversion occurs.
96
+ # * <code>:encoding</code>: Specifies external and internal encodings as
97
+ # <code>'extern:intern'</code>.
98
+ # * <code>:textmode</code>: If a truthy value, specifies the mode as
99
+ # text-only, binary otherwise.
100
+ # * <code>:binmode</code>: If a truthy value, specifies the mode as binary,
101
+ # text-only otherwise.
102
+ # * <code>:autoclose</code>: If a truthy value, specifies that the `fd` will
103
+ # close when the stream closes; otherwise it remains open.
104
+ # * <code>:path:</code> If a string value is provided, it is used in #inspect
105
+ # and is available as #path method.
106
+ #
107
+ # Also available are the options offered in String#encode, which may control
108
+ # conversion between external and internal encoding.
109
+ #
110
+ # ## Basic IO
111
+ #
112
+ # You can perform basic stream IO with these methods, which typically operate on
113
+ # multi-byte strings:
114
+ #
115
+ # * IO#read: Reads and returns some or all of the remaining bytes from the
116
+ # stream.
117
+ # * IO#write: Writes zero or more strings to the stream; each given object
118
+ # that is not already a string is converted via `to_s`.
119
+ #
120
+ # ### Position
121
+ #
122
+ # An IO stream has a nonnegative integer *position*, which is the byte offset at
123
+ # which the next read or write is to occur. A new stream has position zero (and
124
+ # line number zero); method `rewind` resets the position (and line number) to
125
+ # zero.
126
+ #
127
+ # These methods discard [buffers](rdoc-ref:IO@Buffering) and the
128
+ # Encoding::Converter instances used for that IO.
129
+ #
130
+ # The relevant methods:
131
+ #
132
+ # * IO#tell (aliased as <code>#pos</code>): Returns the current position (in
133
+ # bytes) in the stream.
134
+ # * IO#pos=: Sets the position of the stream to a given integer `new_position`
135
+ # (in bytes).
136
+ # * IO#seek: Sets the position of the stream to a given integer `offset` (in
137
+ # bytes), relative to a given position `whence` (indicating the beginning,
138
+ # end, or current position).
139
+ # * IO#rewind: Positions the stream at the beginning (also resetting the line
140
+ # number).
141
+ #
142
+ # ### Open and Closed Streams
143
+ #
144
+ # A new IO stream may be open for reading, open for writing, or both.
145
+ #
146
+ # A stream is automatically closed when claimed by the garbage collector.
147
+ #
148
+ # Attempted reading or writing on a closed stream raises an exception.
149
+ #
150
+ # The relevant methods:
151
+ #
152
+ # * IO#close: Closes the stream for both reading and writing.
153
+ # * IO#close_read: Closes the stream for reading.
154
+ # * IO#close_write: Closes the stream for writing.
155
+ # * IO#closed?: Returns whether the stream is closed.
156
+ #
157
+ # ### End-of-Stream
158
+ #
159
+ # You can query whether a stream is positioned at its end:
160
+ #
161
+ # * IO#eof? (also aliased as <code>#eof</code>): Returns whether the stream is
162
+ # at end-of-stream.
163
+ #
164
+ # You can reposition to end-of-stream by using method IO#seek:
165
+ #
166
+ # f = File.new('t.txt')
167
+ # f.eof? # => false
168
+ # f.seek(0, :END)
169
+ # f.eof? # => true
170
+ # f.close
171
+ #
172
+ # Or by reading all stream content (which is slower than using IO#seek):
173
+ #
174
+ # f.rewind
175
+ # f.eof? # => false
176
+ # f.read # => "First line\nSecond line\n\nFourth line\nFifth line\n"
177
+ # f.eof? # => true
178
+ #
179
+ # ## Line IO
180
+ #
181
+ # Class IO supports line-oriented [input](rdoc-ref:IO@Line+Input) and
182
+ # [output](rdoc-ref:IO@Line+Output)
183
+ #
184
+ # ### Line Input
185
+ #
186
+ # Class IO supports line-oriented input for [files](rdoc-ref:IO@File+Line+Input)
187
+ # and [IO streams](rdoc-ref:IO@Stream+Line+Input)
188
+ #
189
+ # #### File Line Input
190
+ #
191
+ # You can read lines from a file using these methods:
192
+ #
193
+ # * IO.foreach: Reads each line and passes it to the given block.
194
+ # * IO.readlines: Reads and returns all lines in an array.
195
+ #
196
+ # For each of these methods:
197
+ #
198
+ # * You can specify [open options](rdoc-ref:IO@Open+Options).
199
+ # * Line parsing depends on the effective *line separator*; see [Line
200
+ # Separator](rdoc-ref:IO@Line+Separator).
201
+ # * The length of each returned line depends on the effective *line limit*;
202
+ # see [Line Limit](rdoc-ref:IO@Line+Limit).
203
+ #
204
+ # #### Stream Line Input
205
+ #
206
+ # You can read lines from an IO stream using these methods:
207
+ #
208
+ # * IO#each_line: Reads each remaining line, passing it to the given block.
209
+ # * IO#gets: Returns the next line.
210
+ # * IO#readline: Like #gets, but raises an exception at end-of-stream.
211
+ # * IO#readlines: Returns all remaining lines in an array.
212
+ #
213
+ # For each of these methods:
214
+ #
215
+ # * Reading may begin mid-line, depending on the stream's *position*; see
216
+ # [Position](rdoc-ref:IO@Position).
217
+ # * Line parsing depends on the effective *line separator*; see [Line
218
+ # Separator](rdoc-ref:IO@Line+Separator).
219
+ # * The length of each returned line depends on the effective *line limit*;
220
+ # see [Line Limit](rdoc-ref:IO@Line+Limit).
221
+ #
222
+ # ##### Line Separator
223
+ #
224
+ # Each of the [line input methods](rdoc-ref:IO@Line+Input) uses a *line
225
+ # separator*: the string that determines what is considered a line; it is
226
+ # sometimes called the *input record separator*.
227
+ #
228
+ # The default line separator is taken from global variable <code>$/</code>,
229
+ # whose initial value is <code>"\n"</code>.
230
+ #
231
+ # Generally, the line to be read next is all data from the current
232
+ # [position](rdoc-ref:IO@Position) to the next line separator (but see [Special
233
+ # Line Separator Values](rdoc-ref:IO@Special+Line+Separator+Values)):
234
+ #
235
+ # f = File.new('t.txt')
236
+ # # Method gets with no sep argument returns the next line, according to $/.
237
+ # f.gets # => "First line\n"
238
+ # f.gets # => "Second line\n"
239
+ # f.gets # => "\n"
240
+ # f.gets # => "Fourth line\n"
241
+ # f.gets # => "Fifth line\n"
242
+ # f.close
243
+ #
244
+ # You can use a different line separator by passing argument `sep`:
245
+ #
246
+ # f = File.new('t.txt')
247
+ # f.gets('l') # => "First l"
248
+ # f.gets('li') # => "ine\nSecond li"
249
+ # f.gets('lin') # => "ne\n\nFourth lin"
250
+ # f.gets # => "e\n"
251
+ # f.close
252
+ #
253
+ # Or by setting global variable <code>$/</code>:
254
+ #
255
+ # f = File.new('t.txt')
256
+ # $/ = 'l'
257
+ # f.gets # => "First l"
258
+ # f.gets # => "ine\nSecond l"
259
+ # f.gets # => "ine\n\nFourth l"
260
+ # f.close
261
+ #
262
+ # ##### Special Line Separator Values
263
+ #
264
+ # Each of the [line input methods](rdoc-ref:IO@Line+Input) accepts two special
265
+ # values for parameter `sep`:
266
+ #
267
+ # * `nil`: The entire stream is to be read ("slurped") into a single string:
268
+ #
269
+ # f = File.new('t.txt')
270
+ # f.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
271
+ # f.close
272
+ #
273
+ # * <code>''</code> (the empty string): The next "paragraph" is to be read
274
+ # (paragraphs being separated by two consecutive line separators):
275
+ #
276
+ # f = File.new('t.txt')
277
+ # f.gets('') # => "First line\nSecond line\n\n"
278
+ # f.gets('') # => "Fourth line\nFifth line\n"
279
+ # f.close
280
+ #
281
+ # ##### Line Limit
282
+ #
283
+ # Each of the [line input methods](rdoc-ref:IO@Line+Input) uses an integer *line
284
+ # limit*, which restricts the number of bytes that may be returned. (A
285
+ # multi-byte character will not be split, and so a returned line may be slightly
286
+ # longer than the limit).
287
+ #
288
+ # The default limit value is <code>-1</code>; any negative limit value means
289
+ # that there is no limit.
290
+ #
291
+ # If there is no limit, the line is determined only by `sep`.
292
+ #
293
+ # # Text with 1-byte characters.
294
+ # File.open('t.txt') {|f| f.gets(1) } # => "F"
295
+ # File.open('t.txt') {|f| f.gets(2) } # => "Fi"
296
+ # File.open('t.txt') {|f| f.gets(3) } # => "Fir"
297
+ # File.open('t.txt') {|f| f.gets(4) } # => "Firs"
298
+ # # No more than one line.
299
+ # File.open('t.txt') {|f| f.gets(10) } # => "First line"
300
+ # File.open('t.txt') {|f| f.gets(11) } # => "First line\n"
301
+ # File.open('t.txt') {|f| f.gets(12) } # => "First line\n"
302
+ #
303
+ # # Text with 2-byte characters, which will not be split.
304
+ # File.open('t.rus') {|f| f.gets(1).size } # => 1
305
+ # File.open('t.rus') {|f| f.gets(2).size } # => 1
306
+ # File.open('t.rus') {|f| f.gets(3).size } # => 2
307
+ # File.open('t.rus') {|f| f.gets(4).size } # => 2
308
+ #
309
+ # ##### Line Separator and Line Limit
310
+ #
311
+ # With arguments `sep` and `limit` given, combines the two behaviors:
312
+ #
313
+ # * Returns the next line as determined by line separator `sep`.
314
+ # * But returns no more bytes than are allowed by the limit `limit`.
315
+ #
316
+ # Example:
317
+ #
318
+ # File.open('t.txt') {|f| f.gets('li', 20) } # => "First li"
319
+ # File.open('t.txt') {|f| f.gets('li', 2) } # => "Fi"
320
+ #
321
+ # ##### Line Number
322
+ #
323
+ # A readable IO stream has a non-negative integer *line number*:
324
+ #
325
+ # * IO#lineno: Returns the line number.
326
+ # * IO#lineno=: Resets and returns the line number.
327
+ #
328
+ # Unless modified by a call to method IO#lineno=, the line number is the number
329
+ # of lines read by certain line-oriented methods, according to the effective
330
+ # [line separator](rdoc-ref:IO@Line+Separator):
331
+ #
332
+ # * IO.foreach: Increments the line number on each call to the block.
333
+ # * IO#each_line: Increments the line number on each call to the block.
334
+ # * IO#gets: Increments the line number.
335
+ # * IO#readline: Increments the line number.
336
+ # * IO#readlines: Increments the line number for each line read.
337
+ #
338
+ # A new stream is initially has line number zero (and position zero); method
339
+ # `rewind` resets the line number (and position) to zero:
340
+ #
341
+ # f = File.new('t.txt')
342
+ # f.lineno # => 0
343
+ # f.gets # => "First line\n"
344
+ # f.lineno # => 1
345
+ # f.rewind
346
+ # f.lineno # => 0
347
+ # f.close
348
+ #
349
+ # Reading lines from a stream usually changes its line number:
350
+ #
351
+ # f = File.new('t.txt', 'r')
352
+ # f.lineno # => 0
353
+ # f.readline # => "This is line one.\n"
354
+ # f.lineno # => 1
355
+ # f.readline # => "This is the second line.\n"
356
+ # f.lineno # => 2
357
+ # f.readline # => "Here's the third line.\n"
358
+ # f.lineno # => 3
359
+ # f.eof? # => true
360
+ # f.close
361
+ #
362
+ # Iterating over lines in a stream usually changes its line number:
363
+ #
364
+ # File.open('t.txt') do |f|
365
+ # f.each_line do |line|
366
+ # p "position=#{f.pos} eof?=#{f.eof?} lineno=#{f.lineno}"
367
+ # end
368
+ # end
369
+ #
370
+ # Output:
371
+ #
372
+ # "position=11 eof?=false lineno=1"
373
+ # "position=23 eof?=false lineno=2"
374
+ # "position=24 eof?=false lineno=3"
375
+ # "position=36 eof?=false lineno=4"
376
+ # "position=47 eof?=true lineno=5"
377
+ #
378
+ # Unlike the stream's [position](rdoc-ref:IO@Position), the line number does not
379
+ # affect where the next read or write will occur:
380
+ #
381
+ # f = File.new('t.txt')
382
+ # f.lineno = 1000
383
+ # f.lineno # => 1000
384
+ # f.gets # => "First line\n"
385
+ # f.lineno # => 1001
386
+ # f.close
387
+ #
388
+ # Associated with the line number is the global variable <code>$.</code>:
389
+ #
390
+ # * When a stream is opened, <code>$.</code> is not set; its value is left
391
+ # over from previous activity in the process:
392
+ #
393
+ # $. = 41
394
+ # f = File.new('t.txt')
395
+ # $. = 41
396
+ # # => 41
397
+ # f.close
398
+ #
399
+ # * When a stream is read, <code>$.</code> is set to the line number for that
400
+ # stream:
401
+ #
402
+ # f0 = File.new('t.txt')
403
+ # f1 = File.new('t.dat')
404
+ # f0.readlines # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
405
+ # $. # => 5
406
+ # f1.readlines # => ["\xFE\xFF\x99\x90\x99\x91\x99\x92\x99\x93\x99\x94"]
407
+ # $. # => 1
408
+ # f0.close
409
+ # f1.close
410
+ #
411
+ # * Methods IO#rewind and IO#seek do not affect <code>$.</code>:
412
+ #
413
+ # f = File.new('t.txt')
414
+ # f.readlines # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
415
+ # $. # => 5
416
+ # f.rewind
417
+ # f.seek(0, :SET)
418
+ # $. # => 5
419
+ # f.close
420
+ #
421
+ # ### Line Output
422
+ #
423
+ # You can write to an IO stream line-by-line using this method:
424
+ #
425
+ # * IO#puts: Writes objects to the stream.
426
+ #
427
+ # ## Character IO
428
+ #
429
+ # You can process an IO stream character-by-character using these methods:
430
+ #
431
+ # * IO#getc: Reads and returns the next character from the stream.
432
+ # * IO#readchar: Like #getc, but raises an exception at end-of-stream.
433
+ # * IO#ungetc: Pushes back ("unshifts") a character or integer onto the
434
+ # stream.
435
+ # * IO#putc: Writes a character to the stream.
436
+ # * IO#each_char: Reads each remaining character in the stream, passing the
437
+ # character to the given block.
438
+ #
439
+ # ## Byte IO
440
+ #
441
+ # You can process an IO stream byte-by-byte using these methods:
442
+ #
443
+ # * IO#getbyte: Returns the next 8-bit byte as an integer in range 0..255.
444
+ # * IO#readbyte: Like #getbyte, but raises an exception if at end-of-stream.
445
+ # * IO#ungetbyte: Pushes back ("unshifts") a byte back onto the stream.
446
+ # * IO#each_byte: Reads each remaining byte in the stream, passing the byte to
447
+ # the given block.
448
+ #
449
+ # ## Codepoint IO
450
+ #
451
+ # You can process an IO stream codepoint-by-codepoint:
452
+ #
453
+ # * IO#each_codepoint: Reads each remaining codepoint, passing it to the given
454
+ # block.
455
+ #
456
+ # ## What's Here
457
+ #
458
+ # First, what's elsewhere. Class IO:
459
+ #
460
+ # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
461
+ # * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
462
+ # provides dozens of additional methods.
463
+ #
464
+ # Here, class IO provides methods that are useful for:
465
+ #
466
+ # * [Creating](rdoc-ref:IO@Creating)
467
+ # * [Reading](rdoc-ref:IO@Reading)
468
+ # * [Writing](rdoc-ref:IO@Writing)
469
+ # * [Positioning](rdoc-ref:IO@Positioning)
470
+ # * [Iterating](rdoc-ref:IO@Iterating)
471
+ # * [Settings](rdoc-ref:IO@Settings)
472
+ # * [Querying](rdoc-ref:IO@Querying)
473
+ # * [Buffering](rdoc-ref:IO@Buffering)
474
+ # * [Low-Level Access](rdoc-ref:IO@Low-Level+Access)
475
+ # * [Other](rdoc-ref:IO@Other)
476
+ #
477
+ # ### Creating
478
+ #
479
+ # * ::new (aliased as ::for_fd): Creates and returns a new IO object for the
480
+ # given integer file descriptor.
481
+ # * ::open: Creates a new IO object.
482
+ # * ::pipe: Creates a connected pair of reader and writer IO objects.
483
+ # * ::popen: Creates an IO object to interact with a subprocess.
484
+ # * ::select: Selects which given IO instances are ready for reading, writing,
485
+ # or have pending exceptions.
486
+ #
487
+ # ### Reading
488
+ #
489
+ # * ::binread: Returns a binary string with all or a subset of bytes from the
490
+ # given file.
491
+ # * ::read: Returns a string with all or a subset of bytes from the given
492
+ # file.
493
+ # * ::readlines: Returns an array of strings, which are the lines from the
494
+ # given file.
495
+ # * #getbyte: Returns the next 8-bit byte read from `self` as an integer.
496
+ # * #getc: Returns the next character read from `self` as a string.
497
+ # * #gets: Returns the line read from `self`.
498
+ # * #pread: Returns all or the next *n* bytes read from `self`, not updating
499
+ # the receiver's offset.
500
+ # * #read: Returns all remaining or the next *n* bytes read from `self` for a
501
+ # given *n*.
502
+ # * #read_nonblock: the next *n* bytes read from `self` for a given *n*, in
503
+ # non-block mode.
504
+ # * #readbyte: Returns the next byte read from `self`; same as #getbyte, but
505
+ # raises an exception on end-of-stream.
506
+ # * #readchar: Returns the next character read from `self`; same as #getc, but
507
+ # raises an exception on end-of-stream.
508
+ # * #readline: Returns the next line read from `self`; same as #getline, but
509
+ # raises an exception of end-of-stream.
510
+ # * #readlines: Returns an array of all lines read read from `self`.
511
+ # * #readpartial: Returns up to the given number of bytes from `self`.
512
+ #
513
+ # ### Writing
514
+ #
515
+ # * ::binwrite: Writes the given string to the file at the given filepath, in
516
+ # binary mode.
517
+ # * ::write: Writes the given string to `self`.
518
+ # * #<<: Appends the given string to `self`.
519
+ # * #print: Prints last read line or given objects to `self`.
520
+ # * #printf: Writes to `self` based on the given format string and objects.
521
+ # * #putc: Writes a character to `self`.
522
+ # * #puts: Writes lines to `self`, making sure line ends with a newline.
523
+ # * #pwrite: Writes the given string at the given offset, not updating the
524
+ # receiver's offset.
525
+ # * #write: Writes one or more given strings to `self`.
526
+ # * #write_nonblock: Writes one or more given strings to `self` in
527
+ # non-blocking mode.
528
+ #
529
+ # ### Positioning
530
+ #
531
+ # * #lineno: Returns the current line number in `self`.
532
+ # * #lineno=: Sets the line number is `self`.
533
+ # * #pos (aliased as #tell): Returns the current byte offset in `self`.
534
+ # * #pos=: Sets the byte offset in `self`.
535
+ # * #reopen: Reassociates `self` with a new or existing IO stream.
536
+ # * #rewind: Positions `self` to the beginning of input.
537
+ # * #seek: Sets the offset for `self` relative to given position.
538
+ #
539
+ # ### Iterating
540
+ #
541
+ # * ::foreach: Yields each line of given file to the block.
542
+ # * #each (aliased as #each_line): Calls the given block with each successive
543
+ # line in `self`.
544
+ # * #each_byte: Calls the given block with each successive byte in `self` as
545
+ # an integer.
546
+ # * #each_char: Calls the given block with each successive character in `self`
547
+ # as a string.
548
+ # * #each_codepoint: Calls the given block with each successive codepoint in
549
+ # `self` as an integer.
550
+ #
551
+ # ### Settings
552
+ #
553
+ # * #autoclose=: Sets whether `self` auto-closes.
554
+ # * #binmode: Sets `self` to binary mode.
555
+ # * #close: Closes `self`.
556
+ # * #close_on_exec=: Sets the close-on-exec flag.
557
+ # * #close_read: Closes `self` for reading.
558
+ # * #close_write: Closes `self` for writing.
559
+ # * #set_encoding: Sets the encoding for `self`.
560
+ # * #set_encoding_by_bom: Sets the encoding for `self`, based on its Unicode
561
+ # byte-order-mark.
562
+ # * #sync=: Sets the sync-mode to the given value.
563
+ #
564
+ # ### Querying
565
+ #
566
+ # * #autoclose?: Returns whether `self` auto-closes.
567
+ # * #binmode?: Returns whether `self` is in binary mode.
568
+ # * #close_on_exec?: Returns the close-on-exec flag for `self`.
569
+ # * #closed?: Returns whether `self` is closed.
570
+ # * #eof? (aliased as #eof): Returns whether `self` is at end-of-stream.
571
+ # * #external_encoding: Returns the external encoding object for `self`.
572
+ # * #fileno (aliased as #to_i): Returns the integer file descriptor for `self`
573
+ # * #internal_encoding: Returns the internal encoding object for `self`.
574
+ # * #pid: Returns the process ID of a child process associated with `self`, if
575
+ # `self` was created by ::popen.
576
+ # * #stat: Returns the File::Stat object containing status information for
577
+ # `self`.
578
+ # * #sync: Returns whether `self` is in sync-mode.
579
+ # * #tty? (aliased as #isatty): Returns whether `self` is a terminal.
580
+ #
581
+ # ### Buffering
582
+ #
583
+ # * #fdatasync: Immediately writes all buffered data in `self` to disk.
584
+ # * #flush: Flushes any buffered data within `self` to the underlying
585
+ # operating system.
586
+ # * #fsync: Immediately writes all buffered data and attributes in `self` to
587
+ # disk.
588
+ # * #ungetbyte: Prepends buffer for `self` with given integer byte or string.
589
+ # * #ungetc: Prepends buffer for `self` with given string.
590
+ #
591
+ # ### Low-Level Access
592
+ #
593
+ # * ::sysopen: Opens the file given by its path, returning the integer file
594
+ # descriptor.
595
+ # * #advise: Announces the intention to access data from `self` in a specific
596
+ # way.
597
+ # * #fcntl: Passes a low-level command to the file specified by the given file
598
+ # descriptor.
599
+ # * #ioctl: Passes a low-level command to the device specified by the given
600
+ # file descriptor.
601
+ # * #sysread: Returns up to the next *n* bytes read from self using a
602
+ # low-level read.
603
+ # * #sysseek: Sets the offset for `self`.
604
+ # * #syswrite: Writes the given string to `self` using a low-level write.
605
+ #
606
+ # ### Other
607
+ #
608
+ # * ::copy_stream: Copies data from a source to a destination, each of which
609
+ # is a filepath or an IO-like object.
610
+ # * ::try_convert: Returns a new IO object resulting from converting the given
611
+ # object.
612
+ # * #inspect: Returns the string representation of `self`.
613
+ #
614
+ %a{annotate:rdoc:source:from=io.c}
615
+ class IO < Object
616
+ include File::Constants
617
+
618
+ include Enumerable[String]
619
+
620
+ # <!--
621
+ # rdoc-file=io.c
622
+ # - self << object -> self
623
+ # -->
624
+ # Writes the given `object` to `self`, which must be opened for writing (see
625
+ # [Access Modes](rdoc-ref:File@Access+Modes)); returns `self`; if `object` is
626
+ # not a string, it is converted via method `to_s`:
627
+ #
628
+ # $stdout << 'Hello' << ', ' << 'World!' << "\n"
629
+ # $stdout << 'foo' << :bar << 2 << "\n"
630
+ #
631
+ # Output:
632
+ #
633
+ # Hello, World!
634
+ # foobar2
635
+ #
636
+ def <<: (_ToS obj) -> self
637
+
638
+ # <!--
639
+ # rdoc-file=io.c
640
+ # - advise(advice, offset = 0, len = 0) -> nil
641
+ # -->
642
+ # Invokes Posix system call
643
+ # [posix_fadvise(2)](https://linux.die.net/man/2/posix_fadvise), which announces
644
+ # an intention to access data from the current file in a particular manner.
645
+ #
646
+ # The arguments and results are platform-dependent.
647
+ #
648
+ # The relevant data is specified by:
649
+ #
650
+ # * `offset`: The offset of the first byte of data.
651
+ # * `len`: The number of bytes to be accessed; if `len` is zero, or is larger
652
+ # than the number of bytes remaining, all remaining bytes will be accessed.
653
+ #
654
+ # Argument `advice` is one of the following symbols:
655
+ #
656
+ # * <code>:normal</code>: The application has no advice to give about its
657
+ # access pattern for the specified data. If no advice is given for an open
658
+ # file, this is the default assumption.
659
+ # * <code>:sequential</code>: The application expects to access the specified
660
+ # data sequentially (with lower offsets read before higher ones).
661
+ # * <code>:random</code>: The specified data will be accessed in random order.
662
+ # * <code>:noreuse</code>: The specified data will be accessed only once.
663
+ # * <code>:willneed</code>: The specified data will be accessed in the near
664
+ # future.
665
+ # * <code>:dontneed</code>: The specified data will not be accessed in the
666
+ # near future.
667
+ #
668
+ # Not implemented on all platforms.
669
+ #
670
+ def advise: (:normal | :sequential | :random | :willneed | :dontneed | :noreuse advise, ?Integer offset, ?Integer len) -> nil
671
+
672
+ # <!--
673
+ # rdoc-file=io.c
674
+ # - io.autoclose = bool -> true or false
675
+ # -->
676
+ # Sets auto-close flag.
677
+ #
678
+ # f = File.open(File::NULL)
679
+ # IO.for_fd(f.fileno).close
680
+ # f.gets # raises Errno::EBADF
681
+ #
682
+ # f = File.open(File::NULL)
683
+ # g = IO.for_fd(f.fileno)
684
+ # g.autoclose = false
685
+ # g.close
686
+ # f.gets # won't cause Errno::EBADF
687
+ #
688
+ def autoclose=: (boolish bool) -> boolish
689
+
690
+ # <!--
691
+ # rdoc-file=io.c
692
+ # - ios.autoclose? -> true or false
693
+ # -->
694
+ # Returns `true` if the underlying file descriptor of *ios* will be closed at
695
+ # its finalization or at calling #close, otherwise `false`.
696
+ #
697
+ def autoclose?: () -> bool
698
+
699
+ # <!--
700
+ # rdoc-file=io.c
701
+ # - binmode -> self
702
+ # -->
703
+ # Sets the stream's data mode as binary (see [Data
704
+ # Mode](rdoc-ref:File@Data+Mode)).
705
+ #
706
+ # A stream's data mode may not be changed from binary to text.
707
+ #
708
+ def binmode: () -> self
709
+
710
+ # <!--
711
+ # rdoc-file=io.c
712
+ # - binmode? -> true or false
713
+ # -->
714
+ # Returns `true` if the stream is on binary mode, `false` otherwise. See [Data
715
+ # Mode](rdoc-ref:File@Data+Mode).
716
+ #
717
+ def binmode?: () -> bool
718
+
719
+ # <!--
720
+ # rdoc-file=io.c
721
+ # - close -> nil
722
+ # -->
723
+ # Closes the stream for both reading and writing if open for either or both;
724
+ # returns `nil`. See [Open and Closed
725
+ # Streams](rdoc-ref:IO@Open+and+Closed+Streams).
726
+ #
727
+ # If the stream is open for writing, flushes any buffered writes to the
728
+ # operating system before closing.
729
+ #
730
+ # If the stream was opened by IO.popen, sets global variable <code>$?</code>
731
+ # (child exit status).
732
+ #
733
+ # It is not an error to close an IO object that has already been closed. It just
734
+ # returns nil.
735
+ #
736
+ # Example:
737
+ #
738
+ # IO.popen('ruby', 'r+') do |pipe|
739
+ # puts pipe.closed?
740
+ # pipe.close
741
+ # puts $?
742
+ # puts pipe.closed?
743
+ # end
744
+ #
745
+ # Output:
746
+ #
747
+ # false
748
+ # pid 13760 exit 0
749
+ # true
750
+ #
751
+ # Related: IO#close_read, IO#close_write, IO#closed?.
752
+ #
753
+ def close: () -> nil
754
+
755
+ # <!--
756
+ # rdoc-file=io.c
757
+ # - self.close_on_exec = bool -> true or false
758
+ # -->
759
+ # Sets a close-on-exec flag.
760
+ #
761
+ # f = File.open(File::NULL)
762
+ # f.close_on_exec = true
763
+ # system("cat", "/proc/self/fd/#{f.fileno}") # cat: /proc/self/fd/3: No such file or directory
764
+ # f.closed? #=> false
765
+ #
766
+ # Ruby sets close-on-exec flags of all file descriptors by default since Ruby
767
+ # 2.0.0. So you don't need to set by yourself. Also, unsetting a close-on-exec
768
+ # flag can cause file descriptor leak if another thread use fork() and exec()
769
+ # (via system() method for example). If you really needs file descriptor
770
+ # inheritance to child process, use spawn()'s argument such as fd=>fd.
771
+ #
772
+ def close_on_exec=: (boolish bool) -> nil
773
+
774
+ # <!--
775
+ # rdoc-file=io.c
776
+ # - close_on_exec? -> true or false
777
+ # -->
778
+ # Returns `true` if the stream will be closed on exec, `false` otherwise:
779
+ #
780
+ # f = File.open('t.txt')
781
+ # f.close_on_exec? # => true
782
+ # f.close_on_exec = false
783
+ # f.close_on_exec? # => false
784
+ # f.close
785
+ #
786
+ def close_on_exec?: () -> bool
787
+
788
+ # <!--
789
+ # rdoc-file=io.c
790
+ # - close_read -> nil
791
+ # -->
792
+ # Closes the stream for reading if open for reading; returns `nil`. See [Open
793
+ # and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
794
+ #
795
+ # If the stream was opened by IO.popen and is also closed for writing, sets
796
+ # global variable <code>$?</code> (child exit status).
797
+ #
798
+ # Example:
799
+ #
800
+ # IO.popen('ruby', 'r+') do |pipe|
801
+ # puts pipe.closed?
802
+ # pipe.close_write
803
+ # puts pipe.closed?
804
+ # pipe.close_read
805
+ # puts $?
806
+ # puts pipe.closed?
807
+ # end
808
+ #
809
+ # Output:
810
+ #
811
+ # false
812
+ # false
813
+ # pid 14748 exit 0
814
+ # true
815
+ #
816
+ # Related: IO#close, IO#close_write, IO#closed?.
817
+ #
818
+ def close_read: () -> nil
819
+
820
+ # <!--
821
+ # rdoc-file=io.c
822
+ # - close_write -> nil
823
+ # -->
824
+ # Closes the stream for writing if open for writing; returns `nil`. See [Open
825
+ # and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
826
+ #
827
+ # Flushes any buffered writes to the operating system before closing.
828
+ #
829
+ # If the stream was opened by IO.popen and is also closed for reading, sets
830
+ # global variable <code>$?</code> (child exit status).
831
+ #
832
+ # IO.popen('ruby', 'r+') do |pipe|
833
+ # puts pipe.closed?
834
+ # pipe.close_read
835
+ # puts pipe.closed?
836
+ # pipe.close_write
837
+ # puts $?
838
+ # puts pipe.closed?
839
+ # end
840
+ #
841
+ # Output:
842
+ #
843
+ # false
844
+ # false
845
+ # pid 15044 exit 0
846
+ # true
847
+ #
848
+ # Related: IO#close, IO#close_read, IO#closed?.
849
+ #
850
+ def close_write: () -> nil
851
+
852
+ # <!--
853
+ # rdoc-file=io.c
854
+ # - closed? -> true or false
855
+ # -->
856
+ # Returns `true` if the stream is closed for both reading and writing, `false`
857
+ # otherwise. See [Open and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
858
+ #
859
+ # IO.popen('ruby', 'r+') do |pipe|
860
+ # puts pipe.closed?
861
+ # pipe.close_read
862
+ # puts pipe.closed?
863
+ # pipe.close_write
864
+ # puts pipe.closed?
865
+ # end
866
+ #
867
+ # Output:
868
+ #
869
+ # false
870
+ # false
871
+ # true
872
+ #
873
+ # Related: IO#close_read, IO#close_write, IO#close.
874
+ #
875
+ def closed?: () -> bool
876
+
877
+ # <!--
878
+ # rdoc-file=io.c
879
+ # - each_byte {|byte| ... } -> self
880
+ # - each_byte -> enumerator
881
+ # -->
882
+ # Calls the given block with each byte (0..255) in the stream; returns `self`.
883
+ # See [Byte IO](rdoc-ref:IO@Byte+IO).
884
+ #
885
+ # f = File.new('t.rus')
886
+ # a = []
887
+ # f.each_byte {|b| a << b }
888
+ # a # => [209, 130, 208, 181, 209, 129, 209, 130]
889
+ # f.close
890
+ #
891
+ # Returns an Enumerator if no block is given.
892
+ #
893
+ # Related: IO#each_char, IO#each_codepoint.
894
+ #
895
+ def each_byte: () { (Integer byte) -> void } -> self
896
+ | () -> ::Enumerator[Integer, self]
897
+
898
+ # <!--
899
+ # rdoc-file=io.c
900
+ # - each_char {|c| ... } -> self
901
+ # - each_char -> enumerator
902
+ # -->
903
+ # Calls the given block with each character in the stream; returns `self`. See
904
+ # [Character IO](rdoc-ref:IO@Character+IO).
905
+ #
906
+ # f = File.new('t.rus')
907
+ # a = []
908
+ # f.each_char {|c| a << c.ord }
909
+ # a # => [1090, 1077, 1089, 1090]
910
+ # f.close
911
+ #
912
+ # Returns an Enumerator if no block is given.
913
+ #
914
+ # Related: IO#each_byte, IO#each_codepoint.
915
+ #
916
+ def each_char: () { (String c) -> void } -> self
917
+ | () -> ::Enumerator[String, self]
918
+
919
+ # <!--
920
+ # rdoc-file=io.c
921
+ # - each_codepoint {|c| ... } -> self
922
+ # - each_codepoint -> enumerator
923
+ # -->
924
+ # Calls the given block with each codepoint in the stream; returns `self`:
925
+ #
926
+ # f = File.new('t.rus')
927
+ # a = []
928
+ # f.each_codepoint {|c| a << c }
929
+ # a # => [1090, 1077, 1089, 1090]
930
+ # f.close
931
+ #
932
+ # Returns an Enumerator if no block is given.
933
+ #
934
+ # Related: IO#each_byte, IO#each_char.
935
+ #
936
+ def each_codepoint: () { (Integer c) -> void } -> self
937
+ | () -> ::Enumerator[Integer, self]
938
+
939
+ # <!--
940
+ # rdoc-file=io.c
941
+ # - eof -> true or false
942
+ # -->
943
+ # Returns `true` if the stream is positioned at its end, `false` otherwise; see
944
+ # [Position](rdoc-ref:IO@Position):
945
+ #
946
+ # f = File.open('t.txt')
947
+ # f.eof # => false
948
+ # f.seek(0, :END) # => 0
949
+ # f.eof # => true
950
+ # f.close
951
+ #
952
+ # Raises an exception unless the stream is opened for reading; see
953
+ # [Mode](rdoc-ref:File@Access+Modes).
954
+ #
955
+ # If `self` is a stream such as pipe or socket, this method blocks until the
956
+ # other end sends some data or closes it:
957
+ #
958
+ # r, w = IO.pipe
959
+ # Thread.new { sleep 1; w.close }
960
+ # r.eof? # => true # After 1-second wait.
961
+ #
962
+ # r, w = IO.pipe
963
+ # Thread.new { sleep 1; w.puts "a" }
964
+ # r.eof? # => false # After 1-second wait.
965
+ #
966
+ # r, w = IO.pipe
967
+ # r.eof? # blocks forever
968
+ #
969
+ # Note that this method reads data to the input byte buffer. So IO#sysread may
970
+ # not behave as you intend with IO#eof?, unless you call IO#rewind first (which
971
+ # is not available for some streams).
972
+ #
973
+ def eof: () -> bool
974
+
975
+ # <!--
976
+ # rdoc-file=io.c
977
+ # - fcntl(integer_cmd, argument) -> integer
978
+ # -->
979
+ # Invokes Posix system call [fcntl(2)](https://linux.die.net/man/2/fcntl), which
980
+ # provides a mechanism for issuing low-level commands to control or query a
981
+ # file-oriented I/O stream. Arguments and results are platform dependent.
982
+ #
983
+ # If `argument` is a number, its value is passed directly; if it is a string, it
984
+ # is interpreted as a binary sequence of bytes. (Array#pack might be a useful
985
+ # way to build this string.)
986
+ #
987
+ # Not implemented on all platforms.
988
+ #
989
+ def fcntl: (Integer integer_cmd, String | Integer argument) -> Integer
990
+
991
+ # <!--
992
+ # rdoc-file=io.c
993
+ # - fdatasync -> 0
994
+ # -->
995
+ # Immediately writes to disk all data buffered in the stream, via the operating
996
+ # system's: <code>fdatasync(2)</code>, if supported, otherwise via
997
+ # <code>fsync(2)</code>, if supported; otherwise raises an exception.
998
+ #
999
+ def fdatasync: () -> Integer?
1000
+
1001
+ # <!--
1002
+ # rdoc-file=io.c
1003
+ # - fileno -> integer
1004
+ # -->
1005
+ # Returns the integer file descriptor for the stream:
1006
+ #
1007
+ # $stdin.fileno # => 0
1008
+ # $stdout.fileno # => 1
1009
+ # $stderr.fileno # => 2
1010
+ # File.open('t.txt').fileno # => 10
1011
+ # f.close
1012
+ #
1013
+ def fileno: () -> Integer
1014
+
1015
+ # <!--
1016
+ # rdoc-file=io.c
1017
+ # - flush -> self
1018
+ # -->
1019
+ # Flushes data buffered in `self` to the operating system (but does not
1020
+ # necessarily flush data buffered in the operating system):
1021
+ #
1022
+ # $stdout.print 'no newline' # Not necessarily flushed.
1023
+ # $stdout.flush # Flushed.
1024
+ #
1025
+ def flush: () -> self
1026
+
1027
+ # <!--
1028
+ # rdoc-file=io.c
1029
+ # - fsync -> 0
1030
+ # -->
1031
+ # Immediately writes to disk all data buffered in the stream, via the operating
1032
+ # system's <code>fsync(2)</code>.
1033
+ #
1034
+ # Note this difference:
1035
+ #
1036
+ # * IO#sync=: Ensures that data is flushed from the stream's internal buffers,
1037
+ # but does not guarantee that the operating system actually writes the data
1038
+ # to disk.
1039
+ # * IO#fsync: Ensures both that data is flushed from internal buffers, and
1040
+ # that data is written to disk.
1041
+ #
1042
+ # Raises an exception if the operating system does not support
1043
+ # <code>fsync(2)</code>.
1044
+ #
1045
+ def fsync: () -> Integer?
1046
+
1047
+ # <!--
1048
+ # rdoc-file=io.c
1049
+ # - getbyte -> integer or nil
1050
+ # -->
1051
+ # Reads and returns the next byte (in range 0..255) from the stream; returns
1052
+ # `nil` if already at end-of-stream. See [Byte IO](rdoc-ref:IO@Byte+IO).
1053
+ #
1054
+ # f = File.open('t.txt')
1055
+ # f.getbyte # => 70
1056
+ # f.close
1057
+ # f = File.open('t.rus')
1058
+ # f.getbyte # => 209
1059
+ # f.close
1060
+ #
1061
+ # Related: IO#readbyte (may raise EOFError).
1062
+ #
1063
+ def getbyte: () -> Integer?
1064
+
1065
+ # <!--
1066
+ # rdoc-file=io.c
1067
+ # - getc -> character or nil
1068
+ # -->
1069
+ # Reads and returns the next 1-character string from the stream; returns `nil`
1070
+ # if already at end-of-stream. See [Character IO](rdoc-ref:IO@Character+IO).
1071
+ #
1072
+ # f = File.open('t.txt')
1073
+ # f.getc # => "F"
1074
+ # f.close
1075
+ # f = File.open('t.rus')
1076
+ # f.getc.ord # => 1090
1077
+ # f.close
1078
+ #
1079
+ # Related: IO#readchar (may raise EOFError).
1080
+ #
1081
+ def getc: () -> String?
1082
+
1083
+ # <!--
1084
+ # rdoc-file=io.c
1085
+ # - gets(sep = $/, chomp: false) -> string or nil
1086
+ # - gets(limit, chomp: false) -> string or nil
1087
+ # - gets(sep, limit, chomp: false) -> string or nil
1088
+ # -->
1089
+ # Reads and returns a line from the stream; assigns the return value to
1090
+ # <code>$_</code>. See [Line IO](rdoc-ref:IO@Line+IO).
1091
+ #
1092
+ # With no arguments given, returns the next line as determined by line separator
1093
+ # <code>$/</code>, or `nil` if none:
1094
+ #
1095
+ # f = File.open('t.txt')
1096
+ # f.gets # => "First line\n"
1097
+ # $_ # => "First line\n"
1098
+ # f.gets # => "\n"
1099
+ # f.gets # => "Fourth line\n"
1100
+ # f.gets # => "Fifth line\n"
1101
+ # f.gets # => nil
1102
+ # f.close
1103
+ #
1104
+ # With only string argument `sep` given, returns the next line as determined by
1105
+ # line separator `sep`, or `nil` if none; see [Line
1106
+ # Separator](rdoc-ref:IO@Line+Separator):
1107
+ #
1108
+ # f = File.new('t.txt')
1109
+ # f.gets('l') # => "First l"
1110
+ # f.gets('li') # => "ine\nSecond li"
1111
+ # f.gets('lin') # => "ne\n\nFourth lin"
1112
+ # f.gets # => "e\n"
1113
+ # f.close
1114
+ #
1115
+ # The two special values for `sep` are honored:
1116
+ #
1117
+ # f = File.new('t.txt')
1118
+ # # Get all.
1119
+ # f.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1120
+ # f.rewind
1121
+ # # Get paragraph (up to two line separators).
1122
+ # f.gets('') # => "First line\nSecond line\n\n"
1123
+ # f.close
1124
+ #
1125
+ # With only integer argument `limit` given, limits the number of bytes in the
1126
+ # line; see [Line Limit](rdoc-ref:IO@Line+Limit):
1127
+ #
1128
+ # # No more than one line.
1129
+ # File.open('t.txt') {|f| f.gets(10) } # => "First line"
1130
+ # File.open('t.txt') {|f| f.gets(11) } # => "First line\n"
1131
+ # File.open('t.txt') {|f| f.gets(12) } # => "First line\n"
1132
+ #
1133
+ # With arguments `sep` and `limit` given, combines the two behaviors (see [Line
1134
+ # Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
1135
+ #
1136
+ # Optional keyword argument `chomp` specifies whether line separators are to be
1137
+ # omitted:
1138
+ #
1139
+ # f = File.open('t.txt')
1140
+ # # Chomp the lines.
1141
+ # f.gets(chomp: true) # => "First line"
1142
+ # f.gets(chomp: true) # => "Second line"
1143
+ # f.gets(chomp: true) # => ""
1144
+ # f.gets(chomp: true) # => "Fourth line"
1145
+ # f.gets(chomp: true) # => "Fifth line"
1146
+ # f.gets(chomp: true) # => nil
1147
+ # f.close
1148
+ #
1149
+ def gets: (string? sep, ?int limit, ?chomp: boolish) -> String?
1150
+ | (?int limit, ?chomp: boolish) -> String?
1151
+
1152
+ # <!--
1153
+ # rdoc-file=io.c
1154
+ # - IO.new(fd, mode = 'r', **opts) -> io
1155
+ # -->
1156
+ # Creates and returns a new IO object (file stream) from a file descriptor.
1157
+ #
1158
+ # IO.new may be useful for interaction with low-level libraries. For
1159
+ # higher-level interactions, it may be simpler to create the file stream using
1160
+ # File.open.
1161
+ #
1162
+ # Argument `fd` must be a valid file descriptor (integer):
1163
+ #
1164
+ # path = 't.tmp'
1165
+ # fd = IO.sysopen(path) # => 3
1166
+ # IO.new(fd) # => #<IO:fd 3>
1167
+ #
1168
+ # The new IO object does not inherit encoding (because the integer file
1169
+ # descriptor does not have an encoding):
1170
+ #
1171
+ # fd = IO.sysopen('t.rus', 'rb')
1172
+ # io = IO.new(fd)
1173
+ # io.external_encoding # => #<Encoding:UTF-8> # Not ASCII-8BIT.
1174
+ #
1175
+ # Optional argument `mode` (defaults to 'r') must specify a valid mode; see
1176
+ # [Access Modes](rdoc-ref:File@Access+Modes):
1177
+ #
1178
+ # IO.new(fd, 'w') # => #<IO:fd 3>
1179
+ # IO.new(fd, File::WRONLY) # => #<IO:fd 3>
1180
+ #
1181
+ # Optional keyword arguments `opts` specify:
1182
+ #
1183
+ # * [Open Options](rdoc-ref:IO@Open+Options).
1184
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
1185
+ #
1186
+ # Examples:
1187
+ #
1188
+ # IO.new(fd, internal_encoding: nil) # => #<IO:fd 3>
1189
+ # IO.new(fd, autoclose: true) # => #<IO:fd 3>
1190
+ #
1191
+ def initialize: ( int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> void
1192
+
1193
+ # <!--
1194
+ # rdoc-file=io.c
1195
+ # - inspect -> string
1196
+ # -->
1197
+ # Returns a string representation of `self`:
1198
+ #
1199
+ # f = File.open('t.txt')
1200
+ # f.inspect # => "#<File:t.txt>"
1201
+ # f.close
1202
+ #
1203
+ def inspect: () -> String
1204
+
1205
+ # <!--
1206
+ # rdoc-file=io.c
1207
+ # - internal_encoding -> encoding or nil
1208
+ # -->
1209
+ # Returns the Encoding object that represents the encoding of the internal
1210
+ # string, if conversion is specified, or `nil` otherwise.
1211
+ #
1212
+ # See [Encodings](rdoc-ref:File@Encodings).
1213
+ #
1214
+ def internal_encoding: () -> Encoding
1215
+
1216
+ # <!--
1217
+ # rdoc-file=io.c
1218
+ # - ioctl(integer_cmd, argument) -> integer
1219
+ # -->
1220
+ # Invokes Posix system call [ioctl(2)](https://linux.die.net/man/2/ioctl), which
1221
+ # issues a low-level command to an I/O device.
1222
+ #
1223
+ # Issues a low-level command to an I/O device. The arguments and returned value
1224
+ # are platform-dependent. The effect of the call is platform-dependent.
1225
+ #
1226
+ # If argument `argument` is an integer, it is passed directly; if it is a
1227
+ # string, it is interpreted as a binary sequence of bytes.
1228
+ #
1229
+ # Not implemented on all platforms.
1230
+ #
1231
+ def ioctl: (Integer integer_cmd, String | Integer argument) -> Integer
1232
+
1233
+ # <!--
1234
+ # rdoc-file=ext/etc/etc.c
1235
+ # - pathconf(name) -> Integer
1236
+ # -->
1237
+ # Returns pathname configuration variable using fpathconf().
1238
+ #
1239
+ # *name* should be a constant under `Etc` which begins with `PC_`.
1240
+ #
1241
+ # The return value is an integer or nil. nil means indefinite limit.
1242
+ # (fpathconf() returns -1 but errno is not set.)
1243
+ #
1244
+ # require 'etc'
1245
+ # IO.pipe {|r, w|
1246
+ # p w.pathconf(Etc::PC_PIPE_BUF) #=> 4096
1247
+ # }
1248
+ #
1249
+ def pathconf: (Integer name) -> Integer?
1250
+
1251
+ # <!--
1252
+ # rdoc-file=io.c
1253
+ # - isatty -> true or false
1254
+ # -->
1255
+ # Returns `true` if the stream is associated with a terminal device (tty),
1256
+ # `false` otherwise:
1257
+ #
1258
+ # f = File.new('t.txt').isatty #=> false
1259
+ # f.close
1260
+ # f = File.new('/dev/tty').isatty #=> true
1261
+ # f.close
1262
+ #
1263
+ def isatty: () -> bool
1264
+
1265
+ # <!--
1266
+ # rdoc-file=io.c
1267
+ # - lineno -> integer
1268
+ # -->
1269
+ # Returns the current line number for the stream; see [Line
1270
+ # Number](rdoc-ref:IO@Line+Number).
1271
+ #
1272
+ def lineno: () -> Integer
1273
+
1274
+ # <!--
1275
+ # rdoc-file=io.c
1276
+ # - lineno = integer -> integer
1277
+ # -->
1278
+ # Sets and returns the line number for the stream; see [Line
1279
+ # Number](rdoc-ref:IO@Line+Number).
1280
+ #
1281
+ def lineno=: (Integer integer) -> Integer
1282
+
1283
+ # <!--
1284
+ # rdoc-file=io.c
1285
+ # - path -> string or nil
1286
+ # -->
1287
+ # Returns the path associated with the IO, or `nil` if there is no path
1288
+ # associated with the IO. It is not guaranteed that the path exists on the
1289
+ # filesystem.
1290
+ #
1291
+ # $stdin.path # => "<STDIN>"
1292
+ #
1293
+ # File.open("testfile") {|f| f.path} # => "testfile"
1294
+ #
1295
+ def path: () -> String?
1296
+
1297
+ # <!--
1298
+ # rdoc-file=io.c
1299
+ # - pid -> integer or nil
1300
+ # -->
1301
+ # Returns the process ID of a child process associated with the stream, which
1302
+ # will have been set by IO#popen, or `nil` if the stream was not created by
1303
+ # IO#popen:
1304
+ #
1305
+ # pipe = IO.popen("-")
1306
+ # if pipe
1307
+ # $stderr.puts "In parent, child pid is #{pipe.pid}"
1308
+ # else
1309
+ # $stderr.puts "In child, pid is #{$$}"
1310
+ # end
1311
+ #
1312
+ # Output:
1313
+ #
1314
+ # In child, pid is 26209
1315
+ # In parent, child pid is 26209
1316
+ #
1317
+ def pid: () -> Integer
1318
+
1319
+ # <!--
1320
+ # rdoc-file=io.c
1321
+ # - pos = new_position -> new_position
1322
+ # -->
1323
+ # Seeks to the given `new_position` (in bytes); see
1324
+ # [Position](rdoc-ref:IO@Position):
1325
+ #
1326
+ # f = File.open('t.txt')
1327
+ # f.tell # => 0
1328
+ # f.pos = 20 # => 20
1329
+ # f.tell # => 20
1330
+ # f.close
1331
+ #
1332
+ # Related: IO#seek, IO#tell.
1333
+ #
1334
+ def pos=: (Integer new_position) -> Integer
1335
+
1336
+ # <!--
1337
+ # rdoc-file=io.c
1338
+ # - print(*objects) -> nil
1339
+ # -->
1340
+ # Writes the given objects to the stream; returns `nil`. Appends the output
1341
+ # record separator <code>$OUTPUT_RECORD_SEPARATOR</code> (<code>$\</code>), if
1342
+ # it is not `nil`. See [Line IO](rdoc-ref:IO@Line+IO).
1343
+ #
1344
+ # With argument `objects` given, for each object:
1345
+ #
1346
+ # * Converts via its method `to_s` if not a string.
1347
+ # * Writes to the stream.
1348
+ # * If not the last object, writes the output field separator
1349
+ # <code>$OUTPUT_FIELD_SEPARATOR</code> (<code>$,</code>) if it is not `nil`.
1350
+ #
1351
+ # With default separators:
1352
+ #
1353
+ # f = File.open('t.tmp', 'w+')
1354
+ # objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero']
1355
+ # p $OUTPUT_RECORD_SEPARATOR
1356
+ # p $OUTPUT_FIELD_SEPARATOR
1357
+ # f.print(*objects)
1358
+ # f.rewind
1359
+ # p f.read
1360
+ # f.close
1361
+ #
1362
+ # Output:
1363
+ #
1364
+ # nil
1365
+ # nil
1366
+ # "00.00/10+0izerozero"
1367
+ #
1368
+ # With specified separators:
1369
+ #
1370
+ # $\ = "\n"
1371
+ # $, = ','
1372
+ # f.rewind
1373
+ # f.print(*objects)
1374
+ # f.rewind
1375
+ # p f.read
1376
+ #
1377
+ # Output:
1378
+ #
1379
+ # "0,0.0,0/1,0+0i,zero,zero\n"
1380
+ #
1381
+ # With no argument given, writes the content of <code>$_</code> (which is
1382
+ # usually the most recent user input):
1383
+ #
1384
+ # f = File.open('t.tmp', 'w+')
1385
+ # gets # Sets $_ to the most recent user input.
1386
+ # f.print
1387
+ # f.close
1388
+ #
1389
+ def print: (*untyped objects) -> nil
1390
+
1391
+ # <!--
1392
+ # rdoc-file=io.c
1393
+ # - printf(format_string, *objects) -> nil
1394
+ # -->
1395
+ # Formats and writes `objects` to the stream.
1396
+ #
1397
+ # For details on `format_string`, see [Format
1398
+ # Specifications](rdoc-ref:language/format_specifications.rdoc).
1399
+ #
1400
+ def printf: (String format_string, *untyped objects) -> nil
1401
+
1402
+ # <!--
1403
+ # rdoc-file=io.c
1404
+ # - putc(object) -> object
1405
+ # -->
1406
+ # Writes a character to the stream. See [Character
1407
+ # IO](rdoc-ref:IO@Character+IO).
1408
+ #
1409
+ # If `object` is numeric, converts to integer if necessary, then writes the
1410
+ # character whose code is the least significant byte; if `object` is a string,
1411
+ # writes the first character:
1412
+ #
1413
+ # $stdout.putc "A"
1414
+ # $stdout.putc 65
1415
+ #
1416
+ # Output:
1417
+ #
1418
+ # AA
1419
+ #
1420
+ def putc: (Numeric | String object) -> (Numeric | String)
1421
+
1422
+ # <!--
1423
+ # rdoc-file=io.c
1424
+ # - puts(*objects) -> nil
1425
+ # -->
1426
+ # Writes the given `objects` to the stream, which must be open for writing;
1427
+ # returns `nil`.\ Writes a newline after each that does not already end with a
1428
+ # newline sequence. If called without arguments, writes a newline. See [Line
1429
+ # IO](rdoc-ref:IO@Line+IO).
1430
+ #
1431
+ # Note that each added newline is the character <code>"\n"<//tt>, not the output
1432
+ # record separator (<tt>$\</code>).
1433
+ #
1434
+ # Treatment for each object:
1435
+ #
1436
+ # * String: writes the string.
1437
+ # * Neither string nor array: writes <code>object.to_s</code>.
1438
+ # * Array: writes each element of the array; arrays may be nested.
1439
+ #
1440
+ # To keep these examples brief, we define this helper method:
1441
+ #
1442
+ # def show(*objects)
1443
+ # # Puts objects to file.
1444
+ # f = File.new('t.tmp', 'w+')
1445
+ # f.puts(objects)
1446
+ # # Return file content.
1447
+ # f.rewind
1448
+ # p f.read
1449
+ # f.close
1450
+ # end
1451
+ #
1452
+ # # Strings without newlines.
1453
+ # show('foo', 'bar', 'baz') # => "foo\nbar\nbaz\n"
1454
+ # # Strings, some with newlines.
1455
+ # show("foo\n", 'bar', "baz\n") # => "foo\nbar\nbaz\n"
1456
+ #
1457
+ # # Neither strings nor arrays:
1458
+ # show(0, 0.0, Rational(0, 1), Complex(9, 0), :zero)
1459
+ # # => "0\n0.0\n0/1\n9+0i\nzero\n"
1460
+ #
1461
+ # # Array of strings.
1462
+ # show(['foo', "bar\n", 'baz']) # => "foo\nbar\nbaz\n"
1463
+ # # Nested arrays.
1464
+ # show([[[0, 1], 2, 3], 4, 5]) # => "0\n1\n2\n3\n4\n5\n"
1465
+ #
1466
+ def puts: (*untyped objects) -> nil
1467
+
1468
+ # <!--
1469
+ # rdoc-file=io.c
1470
+ # - pread(maxlen, offset) -> string
1471
+ # - pread(maxlen, offset, out_string) -> string
1472
+ # -->
1473
+ # Behaves like IO#readpartial, except that it:
1474
+ #
1475
+ # * Reads at the given `offset` (in bytes).
1476
+ # * Disregards, and does not modify, the stream's position (see
1477
+ # [Position](rdoc-ref:IO@Position)).
1478
+ # * Bypasses any user space buffering in the stream.
1479
+ #
1480
+ # Because this method does not disturb the stream's state (its position, in
1481
+ # particular), `pread` allows multiple threads and processes to use the same IO
1482
+ # object for reading at various offsets.
1483
+ #
1484
+ # f = File.open('t.txt')
1485
+ # f.read # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1486
+ # f.pos # => 52
1487
+ # # Read 12 bytes at offset 0.
1488
+ # f.pread(12, 0) # => "First line\n"
1489
+ # # Read 9 bytes at offset 8.
1490
+ # f.pread(9, 8) # => "ne\nSecon"
1491
+ # f.close
1492
+ #
1493
+ # Not available on some platforms.
1494
+ #
1495
+ def pread: (int maxlen, int offset, ?string? out_string) -> String
1496
+
1497
+ # <!--
1498
+ # rdoc-file=io.c
1499
+ # - pwrite(object, offset) -> integer
1500
+ # -->
1501
+ # Behaves like IO#write, except that it:
1502
+ #
1503
+ # * Writes at the given `offset` (in bytes).
1504
+ # * Disregards, and does not modify, the stream's position (see
1505
+ # [Position](rdoc-ref:IO@Position)).
1506
+ # * Bypasses any user space buffering in the stream.
1507
+ #
1508
+ # Because this method does not disturb the stream's state (its position, in
1509
+ # particular), `pwrite` allows multiple threads and processes to use the same IO
1510
+ # object for writing at various offsets.
1511
+ #
1512
+ # f = File.open('t.tmp', 'w+')
1513
+ # # Write 6 bytes at offset 3.
1514
+ # f.pwrite('ABCDEF', 3) # => 6
1515
+ # f.rewind
1516
+ # f.read # => "\u0000\u0000\u0000ABCDEF"
1517
+ # f.close
1518
+ #
1519
+ # Not available on some platforms.
1520
+ #
1521
+ def pwrite: (_ToS object, int offset) -> Integer
1522
+
1523
+ # <!--
1524
+ # rdoc-file=io.c
1525
+ # - read(maxlen = nil, out_string = nil) -> new_string, out_string, or nil
1526
+ # -->
1527
+ # Reads bytes from the stream; the stream must be opened for reading (see
1528
+ # [Access Modes](rdoc-ref:File@Access+Modes)):
1529
+ #
1530
+ # * If `maxlen` is `nil`, reads all bytes using the stream's data mode.
1531
+ # * Otherwise reads up to `maxlen` bytes in binary mode.
1532
+ #
1533
+ # Returns a string (either a new string or the given `out_string`) containing
1534
+ # the bytes read. The encoding of the string depends on both `maxLen` and
1535
+ # `out_string`:
1536
+ #
1537
+ # * `maxlen` is `nil`: uses internal encoding of `self` (regardless of whether
1538
+ # `out_string` was given).
1539
+ # * `maxlen` not `nil`:
1540
+ #
1541
+ # * `out_string` given: encoding of `out_string` not modified.
1542
+ # * `out_string` not given: ASCII-8BIT is used.
1543
+ #
1544
+ # <strong>Without Argument `out_string`</strong>
1545
+ #
1546
+ # When argument `out_string` is omitted, the returned value is a new string:
1547
+ #
1548
+ # f = File.new('t.txt')
1549
+ # f.read
1550
+ # # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1551
+ # f.rewind
1552
+ # f.read(30) # => "First line\r\nSecond line\r\n\r\nFou"
1553
+ # f.read(30) # => "rth line\r\nFifth line\r\n"
1554
+ # f.read(30) # => nil
1555
+ # f.close
1556
+ #
1557
+ # If `maxlen` is zero, returns an empty string.
1558
+ #
1559
+ # <strong> With Argument `out_string`</strong>
1560
+ #
1561
+ # When argument `out_string` is given, the returned value is `out_string`, whose
1562
+ # content is replaced:
1563
+ #
1564
+ # f = File.new('t.txt')
1565
+ # s = 'foo' # => "foo"
1566
+ # f.read(nil, s) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1567
+ # s # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1568
+ # f.rewind
1569
+ # s = 'bar'
1570
+ # f.read(30, s) # => "First line\r\nSecond line\r\n\r\nFou"
1571
+ # s # => "First line\r\nSecond line\r\n\r\nFou"
1572
+ # s = 'baz'
1573
+ # f.read(30, s) # => "rth line\r\nFifth line\r\n"
1574
+ # s # => "rth line\r\nFifth line\r\n"
1575
+ # s = 'bat'
1576
+ # f.read(30, s) # => nil
1577
+ # s # => ""
1578
+ # f.close
1579
+ #
1580
+ # Note that this method behaves like the fread() function in C. This means it
1581
+ # retries to invoke read(2) system calls to read data with the specified maxlen
1582
+ # (or until EOF).
1583
+ #
1584
+ # This behavior is preserved even if the stream is in non-blocking mode. (This
1585
+ # method is non-blocking-flag insensitive as other methods.)
1586
+ #
1587
+ # If you need the behavior like a single read(2) system call, consider
1588
+ # #readpartial, #read_nonblock, and #sysread.
1589
+ #
1590
+ # Related: IO#write.
1591
+ #
1592
+ def read: (?nil, ?string? outbuf) -> String
1593
+ | (int? length, ?string? outbuf) -> String?
1594
+
1595
+ # <!--
1596
+ # rdoc-file=io.rb
1597
+ # - ios.read_nonblock(maxlen [, options]) -> string
1598
+ # - ios.read_nonblock(maxlen, outbuf [, options]) -> outbuf
1599
+ # -->
1600
+ # Reads at most *maxlen* bytes from *ios* using the read(2) system call after
1601
+ # O_NONBLOCK is set for the underlying file descriptor.
1602
+ #
1603
+ # If the optional *outbuf* argument is present, it must reference a String,
1604
+ # which will receive the data. The *outbuf* will contain only the received data
1605
+ # after the method call even if it is not empty at the beginning.
1606
+ #
1607
+ # read_nonblock just calls the read(2) system call. It causes all errors the
1608
+ # read(2) system call causes: Errno::EWOULDBLOCK, Errno::EINTR, etc. The caller
1609
+ # should care such errors.
1610
+ #
1611
+ # If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by
1612
+ # IO::WaitReadable. So IO::WaitReadable can be used to rescue the exceptions for
1613
+ # retrying read_nonblock.
1614
+ #
1615
+ # read_nonblock causes EOFError on EOF.
1616
+ #
1617
+ # On some platforms, such as Windows, non-blocking mode is not supported on IO
1618
+ # objects other than sockets. In such cases, Errno::EBADF will be raised.
1619
+ #
1620
+ # If the read byte buffer is not empty, read_nonblock reads from the buffer like
1621
+ # readpartial. In this case, the read(2) system call is not called.
1622
+ #
1623
+ # When read_nonblock raises an exception kind of IO::WaitReadable, read_nonblock
1624
+ # should not be called until io is readable for avoiding busy loop. This can be
1625
+ # done as follows.
1626
+ #
1627
+ # # emulates blocking read (readpartial).
1628
+ # begin
1629
+ # result = io.read_nonblock(maxlen)
1630
+ # rescue IO::WaitReadable
1631
+ # IO.select([io])
1632
+ # retry
1633
+ # end
1634
+ #
1635
+ # Although IO#read_nonblock doesn't raise IO::WaitWritable.
1636
+ # OpenSSL::Buffering#read_nonblock can raise IO::WaitWritable. If IO and SSL
1637
+ # should be used polymorphically, IO::WaitWritable should be rescued too. See
1638
+ # the document of OpenSSL::Buffering#read_nonblock for sample code.
1639
+ #
1640
+ # Note that this method is identical to readpartial except the non-blocking flag
1641
+ # is set.
1642
+ #
1643
+ # By specifying a keyword argument *exception* to `false`, you can indicate that
1644
+ # read_nonblock should not raise an IO::WaitReadable exception, but return the
1645
+ # symbol <code>:wait_readable</code> instead. At EOF, it will return nil instead
1646
+ # of raising EOFError.
1647
+ #
1648
+ def read_nonblock: (int len, ?string? buf, ?exception: true) -> String
1649
+ | (int len, ?string? buf, exception: false) -> (String | :wait_readable | nil)
1650
+
1651
+ # <!--
1652
+ # rdoc-file=io.c
1653
+ # - readbyte -> integer
1654
+ # -->
1655
+ # Reads and returns the next byte (in range 0..255) from the stream; raises
1656
+ # EOFError if already at end-of-stream. See [Byte IO](rdoc-ref:IO@Byte+IO).
1657
+ #
1658
+ # f = File.open('t.txt')
1659
+ # f.readbyte # => 70
1660
+ # f.close
1661
+ # f = File.open('t.rus')
1662
+ # f.readbyte # => 209
1663
+ # f.close
1664
+ #
1665
+ # Related: IO#getbyte (will not raise EOFError).
1666
+ #
1667
+ def readbyte: () -> Integer
1668
+
1669
+ # <!--
1670
+ # rdoc-file=io.c
1671
+ # - readchar -> string
1672
+ # -->
1673
+ # Reads and returns the next 1-character string from the stream; raises EOFError
1674
+ # if already at end-of-stream. See [Character IO](rdoc-ref:IO@Character+IO).
1675
+ #
1676
+ # f = File.open('t.txt')
1677
+ # f.readchar # => "F"
1678
+ # f.close
1679
+ # f = File.open('t.rus')
1680
+ # f.readchar.ord # => 1090
1681
+ # f.close
1682
+ #
1683
+ # Related: IO#getc (will not raise EOFError).
1684
+ #
1685
+ def readchar: () -> String
1686
+
1687
+ # <!--
1688
+ # rdoc-file=io.rb
1689
+ # - readline(sep = $/, chomp: false) -> string
1690
+ # - readline(limit, chomp: false) -> string
1691
+ # - readline(sep, limit, chomp: false) -> string
1692
+ # -->
1693
+ # Reads a line as with IO#gets, but raises EOFError if already at end-of-stream.
1694
+ #
1695
+ # Optional keyword argument `chomp` specifies whether line separators are to be
1696
+ # omitted.
1697
+ #
1698
+ def readline: (?String sep, ?Integer limit, ?chomp: boolish) -> String
1699
+
1700
+ # <!--
1701
+ # rdoc-file=io.c
1702
+ # - readlines(sep = $/, chomp: false) -> array
1703
+ # - readlines(limit, chomp: false) -> array
1704
+ # - readlines(sep, limit, chomp: false) -> array
1705
+ # -->
1706
+ # Reads and returns all remaining line from the stream; does not modify
1707
+ # <code>$_</code>. See [Line IO](rdoc-ref:IO@Line+IO).
1708
+ #
1709
+ # With no arguments given, returns lines as determined by line separator
1710
+ # <code>$/</code>, or `nil` if none:
1711
+ #
1712
+ # f = File.new('t.txt')
1713
+ # f.readlines
1714
+ # # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
1715
+ # f.readlines # => []
1716
+ # f.close
1717
+ #
1718
+ # With only string argument `sep` given, returns lines as determined by line
1719
+ # separator `sep`, or `nil` if none; see [Line
1720
+ # Separator](rdoc-ref:IO@Line+Separator):
1721
+ #
1722
+ # f = File.new('t.txt')
1723
+ # f.readlines('li')
1724
+ # # => ["First li", "ne\nSecond li", "ne\n\nFourth li", "ne\nFifth li", "ne\n"]
1725
+ # f.close
1726
+ #
1727
+ # The two special values for `sep` are honored:
1728
+ #
1729
+ # f = File.new('t.txt')
1730
+ # # Get all into one string.
1731
+ # f.readlines(nil)
1732
+ # # => ["First line\nSecond line\n\nFourth line\nFifth line\n"]
1733
+ # # Get paragraphs (up to two line separators).
1734
+ # f.rewind
1735
+ # f.readlines('')
1736
+ # # => ["First line\nSecond line\n\n", "Fourth line\nFifth line\n"]
1737
+ # f.close
1738
+ #
1739
+ # With only integer argument `limit` given, limits the number of bytes in each
1740
+ # line; see [Line Limit](rdoc-ref:IO@Line+Limit):
1741
+ #
1742
+ # f = File.new('t.txt')
1743
+ # f.readlines(8)
1744
+ # # => ["First li", "ne\n", "Second l", "ine\n", "\n", "Fourth l", "ine\n", "Fifth li", "ne\n"]
1745
+ # f.close
1746
+ #
1747
+ # With arguments `sep` and `limit` given, combines the two behaviors (see [Line
1748
+ # Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
1749
+ #
1750
+ # Optional keyword argument `chomp` specifies whether line separators are to be
1751
+ # omitted:
1752
+ #
1753
+ # f = File.new('t.txt')
1754
+ # f.readlines(chomp: true)
1755
+ # # => ["First line", "Second line", "", "Fourth line", "Fifth line"]
1756
+ # f.close
1757
+ #
1758
+ def readlines: (?String sep, ?Integer limit, ?chomp: boolish) -> ::Array[String]
1759
+
1760
+ # <!--
1761
+ # rdoc-file=io.c
1762
+ # - readpartial(maxlen) -> string
1763
+ # - readpartial(maxlen, out_string) -> out_string
1764
+ # -->
1765
+ # Reads up to `maxlen` bytes from the stream; returns a string (either a new
1766
+ # string or the given `out_string`). Its encoding is:
1767
+ #
1768
+ # * The unchanged encoding of `out_string`, if `out_string` is given.
1769
+ # * ASCII-8BIT, otherwise.
1770
+ #
1771
+ # * Contains `maxlen` bytes from the stream, if available.
1772
+ # * Otherwise contains all available bytes, if any available.
1773
+ # * Otherwise is an empty string.
1774
+ #
1775
+ # With the single non-negative integer argument `maxlen` given, returns a new
1776
+ # string:
1777
+ #
1778
+ # f = File.new('t.txt')
1779
+ # f.readpartial(20) # => "First line\nSecond l"
1780
+ # f.readpartial(20) # => "ine\n\nFourth line\n"
1781
+ # f.readpartial(20) # => "Fifth line\n"
1782
+ # f.readpartial(20) # Raises EOFError.
1783
+ # f.close
1784
+ #
1785
+ # With both argument `maxlen` and string argument `out_string` given, returns
1786
+ # modified `out_string`:
1787
+ #
1788
+ # f = File.new('t.txt')
1789
+ # s = 'foo'
1790
+ # f.readpartial(20, s) # => "First line\nSecond l"
1791
+ # s = 'bar'
1792
+ # f.readpartial(0, s) # => ""
1793
+ # f.close
1794
+ #
1795
+ # This method is useful for a stream such as a pipe, a socket, or a tty. It
1796
+ # blocks only when no data is immediately available. This means that it blocks
1797
+ # only when *all* of the following are true:
1798
+ #
1799
+ # * The byte buffer in the stream is empty.
1800
+ # * The content of the stream is empty.
1801
+ # * The stream is not at EOF.
1802
+ #
1803
+ # When blocked, the method waits for either more data or EOF on the stream:
1804
+ #
1805
+ # * If more data is read, the method returns the data.
1806
+ # * If EOF is reached, the method raises EOFError.
1807
+ #
1808
+ # When not blocked, the method responds immediately:
1809
+ #
1810
+ # * Returns data from the buffer if there is any.
1811
+ # * Otherwise returns data from the stream if there is any.
1812
+ # * Otherwise raises EOFError if the stream has reached EOF.
1813
+ #
1814
+ # Note that this method is similar to sysread. The differences are:
1815
+ #
1816
+ # * If the byte buffer is not empty, read from the byte buffer instead of
1817
+ # "sysread for buffered IO (IOError)".
1818
+ # * It doesn't cause Errno::EWOULDBLOCK and Errno::EINTR. When readpartial
1819
+ # meets EWOULDBLOCK and EINTR by read system call, readpartial retries the
1820
+ # system call.
1821
+ #
1822
+ # The latter means that readpartial is non-blocking-flag insensitive. It blocks
1823
+ # on the situation IO#sysread causes Errno::EWOULDBLOCK as if the fd is blocking
1824
+ # mode.
1825
+ #
1826
+ # Examples:
1827
+ #
1828
+ # # # Returned Buffer Content Pipe Content
1829
+ # r, w = IO.pipe #
1830
+ # w << 'abc' # "" "abc".
1831
+ # r.readpartial(4096) # => "abc" "" ""
1832
+ # r.readpartial(4096) # (Blocks because buffer and pipe are empty.)
1833
+ #
1834
+ # # # Returned Buffer Content Pipe Content
1835
+ # r, w = IO.pipe #
1836
+ # w << 'abc' # "" "abc"
1837
+ # w.close # "" "abc" EOF
1838
+ # r.readpartial(4096) # => "abc" "" EOF
1839
+ # r.readpartial(4096) # raises EOFError
1840
+ #
1841
+ # # # Returned Buffer Content Pipe Content
1842
+ # r, w = IO.pipe #
1843
+ # w << "abc\ndef\n" # "" "abc\ndef\n"
1844
+ # r.gets # => "abc\n" "def\n" ""
1845
+ # w << "ghi\n" # "def\n" "ghi\n"
1846
+ # r.readpartial(4096) # => "def\n" "" "ghi\n"
1847
+ # r.readpartial(4096) # => "ghi\n" "" ""
1848
+ #
1849
+ def readpartial: (int maxlen, ?string? outbuf) -> String
1850
+
1851
+ # <!--
1852
+ # rdoc-file=io.c
1853
+ # - reopen(other_io) -> self
1854
+ # - reopen(path, mode = 'r', **opts) -> self
1855
+ # -->
1856
+ # Reassociates the stream with another stream, which may be of a different
1857
+ # class. This method may be used to redirect an existing stream to a new
1858
+ # destination.
1859
+ #
1860
+ # With argument `other_io` given, reassociates with that stream:
1861
+ #
1862
+ # # Redirect $stdin from a file.
1863
+ # f = File.open('t.txt')
1864
+ # $stdin.reopen(f)
1865
+ # f.close
1866
+ #
1867
+ # # Redirect $stdout to a file.
1868
+ # f = File.open('t.tmp', 'w')
1869
+ # $stdout.reopen(f)
1870
+ # f.close
1871
+ #
1872
+ # With argument `path` given, reassociates with a new stream to that file path:
1873
+ #
1874
+ # $stdin.reopen('t.txt')
1875
+ # $stdout.reopen('t.tmp', 'w')
1876
+ #
1877
+ # Optional keyword arguments `opts` specify:
1878
+ #
1879
+ # * [Open Options](rdoc-ref:IO@Open+Options).
1880
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
1881
+ #
1882
+ def reopen: (IO other_IO_or_path) -> IO
1883
+ | (String other_IO_or_path, ?String mode_str) -> IO
1884
+
1885
+ # <!--
1886
+ # rdoc-file=io.c
1887
+ # - rewind -> 0
1888
+ # -->
1889
+ # Repositions the stream to its beginning, setting both the position and the
1890
+ # line number to zero; see [Position](rdoc-ref:IO@Position) and [Line
1891
+ # Number](rdoc-ref:IO@Line+Number):
1892
+ #
1893
+ # f = File.open('t.txt')
1894
+ # f.tell # => 0
1895
+ # f.lineno # => 0
1896
+ # f.gets # => "First line\n"
1897
+ # f.tell # => 12
1898
+ # f.lineno # => 1
1899
+ # f.rewind # => 0
1900
+ # f.tell # => 0
1901
+ # f.lineno # => 0
1902
+ # f.close
1903
+ #
1904
+ # Note that this method cannot be used with streams such as pipes, ttys, and
1905
+ # sockets.
1906
+ #
1907
+ def rewind: () -> Integer
1908
+
1909
+ # <!--
1910
+ # rdoc-file=io.c
1911
+ # - seek(offset, whence = IO::SEEK_SET) -> 0
1912
+ # -->
1913
+ # Seeks to the position given by integer `offset` (see
1914
+ # [Position](rdoc-ref:IO@Position)) and constant `whence`, which is one of:
1915
+ #
1916
+ # * <code>:CUR</code> or <code>IO::SEEK_CUR</code>: Repositions the stream to
1917
+ # its current position plus the given `offset`:
1918
+ #
1919
+ # f = File.open('t.txt')
1920
+ # f.tell # => 0
1921
+ # f.seek(20, :CUR) # => 0
1922
+ # f.tell # => 20
1923
+ # f.seek(-10, :CUR) # => 0
1924
+ # f.tell # => 10
1925
+ # f.close
1926
+ #
1927
+ # * <code>:END</code> or <code>IO::SEEK_END</code>: Repositions the stream to
1928
+ # its end plus the given `offset`:
1929
+ #
1930
+ # f = File.open('t.txt')
1931
+ # f.tell # => 0
1932
+ # f.seek(0, :END) # => 0 # Repositions to stream end.
1933
+ # f.tell # => 52
1934
+ # f.seek(-20, :END) # => 0
1935
+ # f.tell # => 32
1936
+ # f.seek(-40, :END) # => 0
1937
+ # f.tell # => 12
1938
+ # f.close
1939
+ #
1940
+ # * <code>:SET</code> or <code>IO:SEEK_SET</code>: Repositions the stream to
1941
+ # the given `offset`:
1942
+ #
1943
+ # f = File.open('t.txt')
1944
+ # f.tell # => 0
1945
+ # f.seek(20, :SET) # => 0
1946
+ # f.tell # => 20
1947
+ # f.seek(40, :SET) # => 0
1948
+ # f.tell # => 40
1949
+ # f.close
1950
+ #
1951
+ # Related: IO#pos=, IO#tell.
1952
+ #
1953
+ def seek: (Integer amount, ?Integer whence) -> Integer
1954
+
1955
+ # <!--
1956
+ # rdoc-file=io.c
1957
+ # - set_encoding(ext_enc) -> self
1958
+ # - set_encoding(ext_enc, int_enc, **enc_opts) -> self
1959
+ # - set_encoding('ext_enc:int_enc', **enc_opts) -> self
1960
+ # -->
1961
+ # See [Encodings](rdoc-ref:File@Encodings).
1962
+ #
1963
+ # Argument `ext_enc`, if given, must be an Encoding object or a String with the
1964
+ # encoding name; it is assigned as the encoding for the stream.
1965
+ #
1966
+ # Argument `int_enc`, if given, must be an Encoding object or a String with the
1967
+ # encoding name; it is assigned as the encoding for the internal string.
1968
+ #
1969
+ # Argument <code>'ext_enc:int_enc'</code>, if given, is a string containing two
1970
+ # colon-separated encoding names; corresponding Encoding objects are assigned as
1971
+ # the external and internal encodings for the stream.
1972
+ #
1973
+ # If the external encoding of a string is binary/ASCII-8BIT, the internal
1974
+ # encoding of the string is set to nil, since no transcoding is needed.
1975
+ #
1976
+ # Optional keyword arguments `enc_opts` specify [Encoding
1977
+ # options](rdoc-ref:encodings.rdoc@Encoding+Options).
1978
+ #
1979
+ def set_encoding: (?String | Encoding ext_or_ext_int_enc) -> self
1980
+ | (?String | Encoding ext_or_ext_int_enc, ?String | Encoding int_enc) -> self
1981
+
1982
+ # <!--
1983
+ # rdoc-file=io.c
1984
+ # - set_encoding_by_bom -> encoding or nil
1985
+ # -->
1986
+ # If the stream begins with a BOM ([byte order
1987
+ # marker](https://en.wikipedia.org/wiki/Byte_order_mark)), consumes the BOM and
1988
+ # sets the external encoding accordingly; returns the result encoding if found,
1989
+ # or `nil` otherwise:
1990
+ #
1991
+ # File.write('t.tmp', "\u{FEFF}abc")
1992
+ # io = File.open('t.tmp', 'rb')
1993
+ # io.set_encoding_by_bom # => #<Encoding:UTF-8>
1994
+ # io.close
1995
+ #
1996
+ # File.write('t.tmp', 'abc')
1997
+ # io = File.open('t.tmp', 'rb')
1998
+ # io.set_encoding_by_bom # => nil
1999
+ # io.close
2000
+ #
2001
+ # Raises an exception if the stream is not binmode or its encoding has already
2002
+ # been set.
2003
+ #
2004
+ def set_encoding_by_bom: () -> Encoding?
2005
+
2006
+ # <!--
2007
+ # rdoc-file=file.c
2008
+ # - ios.stat -> stat
2009
+ # -->
2010
+ # Returns status information for *ios* as an object of type File::Stat.
2011
+ #
2012
+ # f = File.new("testfile")
2013
+ # s = f.stat
2014
+ # "%o" % s.mode #=> "100644"
2015
+ # s.blksize #=> 4096
2016
+ # s.atime #=> Wed Apr 09 08:53:54 CDT 2003
2017
+ #
2018
+ def stat: () -> File::Stat
2019
+
2020
+ # <!--
2021
+ # rdoc-file=io.c
2022
+ # - sync -> true or false
2023
+ # -->
2024
+ # Returns the current sync mode of the stream. When sync mode is true, all
2025
+ # output is immediately flushed to the underlying operating system and is not
2026
+ # buffered by Ruby internally. See also #fsync.
2027
+ #
2028
+ # f = File.open('t.tmp', 'w')
2029
+ # f.sync # => false
2030
+ # f.sync = true
2031
+ # f.sync # => true
2032
+ # f.close
2033
+ #
2034
+ def sync: () -> bool
2035
+
2036
+ # <!--
2037
+ # rdoc-file=io.c
2038
+ # - sync = boolean -> boolean
2039
+ # -->
2040
+ # Sets the *sync* *mode* for the stream to the given value; returns the given
2041
+ # value.
2042
+ #
2043
+ # Values for the sync mode:
2044
+ #
2045
+ # * `true`: All output is immediately flushed to the underlying operating
2046
+ # system and is not buffered internally.
2047
+ # * `false`: Output may be buffered internally.
2048
+ #
2049
+ # Example;
2050
+ #
2051
+ # f = File.open('t.tmp', 'w')
2052
+ # f.sync # => false
2053
+ # f.sync = true
2054
+ # f.sync # => true
2055
+ # f.close
2056
+ #
2057
+ # Related: IO#fsync.
2058
+ #
2059
+ def sync=: (boolish boolean) -> boolish
2060
+
2061
+ # <!--
2062
+ # rdoc-file=io.c
2063
+ # - sysread(maxlen) -> string
2064
+ # - sysread(maxlen, out_string) -> string
2065
+ # -->
2066
+ # Behaves like IO#readpartial, except that it uses low-level system functions.
2067
+ #
2068
+ # This method should not be used with other stream-reader methods.
2069
+ #
2070
+ def sysread: (Integer maxlen, ?String? outbuf) -> String
2071
+
2072
+ # <!--
2073
+ # rdoc-file=io.c
2074
+ # - sysseek(offset, whence = IO::SEEK_SET) -> integer
2075
+ # -->
2076
+ # Behaves like IO#seek, except that it:
2077
+ #
2078
+ # * Uses low-level system functions.
2079
+ # * Returns the new position.
2080
+ #
2081
+ def sysseek: (Integer amount, ?Integer whence) -> Integer
2082
+
2083
+ # <!--
2084
+ # rdoc-file=io.c
2085
+ # - syswrite(object) -> integer
2086
+ # -->
2087
+ # Writes the given `object` to self, which must be opened for writing (see
2088
+ # Modes); returns the number bytes written. If `object` is not a string is
2089
+ # converted via method to_s:
2090
+ #
2091
+ # f = File.new('t.tmp', 'w')
2092
+ # f.syswrite('foo') # => 3
2093
+ # f.syswrite(30) # => 2
2094
+ # f.syswrite(:foo) # => 3
2095
+ # f.close
2096
+ #
2097
+ # This methods should not be used with other stream-writer methods.
2098
+ #
2099
+ def syswrite: (_ToS object) -> Integer
2100
+
2101
+ # <!--
2102
+ # rdoc-file=io.c
2103
+ # - tell -> integer
2104
+ # -->
2105
+ # Returns the current position (in bytes) in `self` (see
2106
+ # [Position](rdoc-ref:IO@Position)):
2107
+ #
2108
+ # f = File.open('t.txt')
2109
+ # f.tell # => 0
2110
+ # f.gets # => "First line\n"
2111
+ # f.tell # => 12
2112
+ # f.close
2113
+ #
2114
+ # Related: IO#pos=, IO#seek.
2115
+ #
2116
+ def tell: () -> Integer
2117
+
2118
+ # <!-- rdoc-file=io.c -->
2119
+ # Returns the current position (in bytes) in `self` (see
2120
+ # [Position](rdoc-ref:IO@Position)):
2121
+ #
2122
+ # f = File.open('t.txt')
2123
+ # f.tell # => 0
2124
+ # f.gets # => "First line\n"
2125
+ # f.tell # => 12
2126
+ # f.close
2127
+ #
2128
+ # Related: IO#pos=, IO#seek.
2129
+ #
2130
+ alias pos tell
2131
+
2132
+ # <!--
2133
+ # rdoc-file=io.c
2134
+ # - timeout -> duration or nil
2135
+ # -->
2136
+ # Get the internal timeout duration or nil if it was not set.
2137
+ #
2138
+ def timeout: () -> io_timeout
2139
+
2140
+ # The type used for timeouts in `IO`.
2141
+ #
2142
+ # Technically, this type should be `Time::_Timeout?`. However, in the vast majority of use-cases,
2143
+ # people aren't going to pass their own `_Timeout` in, so `Numeric` is returned for ergonomics
2144
+ # (eg `io.timeout += 10`).
2145
+ type io_timeout = Numeric?
2146
+
2147
+ # <!--
2148
+ # rdoc-file=io.c
2149
+ # - timeout = duration -> duration
2150
+ # - timeout = nil -> nil
2151
+ # -->
2152
+ # Sets the internal timeout to the specified duration or nil. The timeout
2153
+ # applies to all blocking operations where possible.
2154
+ #
2155
+ # When the operation performs longer than the timeout set, IO::TimeoutError is
2156
+ # raised.
2157
+ #
2158
+ # This affects the following methods (but is not limited to): #gets, #puts,
2159
+ # #read, #write, #wait_readable and #wait_writable. This also affects blocking
2160
+ # socket operations like Socket#accept and Socket#connect.
2161
+ #
2162
+ # Some operations like File#open and IO#close are not affected by the timeout. A
2163
+ # timeout during a write operation may leave the IO in an inconsistent state,
2164
+ # e.g. data was partially written. Generally speaking, a timeout is a last ditch
2165
+ # effort to prevent an application from hanging on slow I/O operations, such as
2166
+ # those that occur during a slowloris attack.
2167
+ #
2168
+ def timeout=: (io_timeout duration) -> void
2169
+
2170
+ # <!--
2171
+ # rdoc-file=io.c
2172
+ # - to_io -> self
2173
+ # -->
2174
+ # Returns `self`.
2175
+ #
2176
+ def to_io: () -> self
2177
+
2178
+ # <!-- rdoc-file=io.c -->
2179
+ # Returns `true` if the stream is associated with a terminal device (tty),
2180
+ # `false` otherwise:
2181
+ #
2182
+ # f = File.new('t.txt').isatty #=> false
2183
+ # f.close
2184
+ # f = File.new('/dev/tty').isatty #=> true
2185
+ # f.close
2186
+ #
2187
+ alias tty? isatty
2188
+
2189
+ # <!--
2190
+ # rdoc-file=io.c
2191
+ # - ungetbyte(integer) -> nil
2192
+ # - ungetbyte(string) -> nil
2193
+ # -->
2194
+ # Pushes back ("unshifts") the given data onto the stream's buffer, placing the
2195
+ # data so that it is next to be read; returns `nil`. See [Byte
2196
+ # IO](rdoc-ref:IO@Byte+IO).
2197
+ #
2198
+ # Note that:
2199
+ #
2200
+ # * Calling the method has no effect with unbuffered reads (such as
2201
+ # IO#sysread).
2202
+ # * Calling #rewind on the stream discards the pushed-back data.
2203
+ #
2204
+ # When argument `integer` is given, uses only its low-order byte:
2205
+ #
2206
+ # File.write('t.tmp', '012')
2207
+ # f = File.open('t.tmp')
2208
+ # f.ungetbyte(0x41) # => nil
2209
+ # f.read # => "A012"
2210
+ # f.rewind
2211
+ # f.ungetbyte(0x4243) # => nil
2212
+ # f.read # => "C012"
2213
+ # f.close
2214
+ #
2215
+ # When argument `string` is given, uses all bytes:
2216
+ #
2217
+ # File.write('t.tmp', '012')
2218
+ # f = File.open('t.tmp')
2219
+ # f.ungetbyte('A') # => nil
2220
+ # f.read # => "A012"
2221
+ # f.rewind
2222
+ # f.ungetbyte('BCDE') # => nil
2223
+ # f.read # => "BCDE012"
2224
+ # f.close
2225
+ #
2226
+ def ungetbyte: (String | Integer object) -> nil
2227
+
2228
+ # <!--
2229
+ # rdoc-file=io.c
2230
+ # - ungetc(integer) -> nil
2231
+ # - ungetc(string) -> nil
2232
+ # -->
2233
+ # Pushes back ("unshifts") the given data onto the stream's buffer, placing the
2234
+ # data so that it is next to be read; returns `nil`. See [Character
2235
+ # IO](rdoc-ref:IO@Character+IO).
2236
+ #
2237
+ # Note that:
2238
+ #
2239
+ # * Calling the method has no effect with unbuffered reads (such as
2240
+ # IO#sysread).
2241
+ # * Calling #rewind on the stream discards the pushed-back data.
2242
+ #
2243
+ # When argument `integer` is given, interprets the integer as a character:
2244
+ #
2245
+ # File.write('t.tmp', '012')
2246
+ # f = File.open('t.tmp')
2247
+ # f.ungetc(0x41) # => nil
2248
+ # f.read # => "A012"
2249
+ # f.rewind
2250
+ # f.ungetc(0x0442) # => nil
2251
+ # f.getc.ord # => 1090
2252
+ # f.close
2253
+ #
2254
+ # When argument `string` is given, uses all characters:
2255
+ #
2256
+ # File.write('t.tmp', '012')
2257
+ # f = File.open('t.tmp')
2258
+ # f.ungetc('A') # => nil
2259
+ # f.read # => "A012"
2260
+ # f.rewind
2261
+ # f.ungetc("\u0442\u0435\u0441\u0442") # => nil
2262
+ # f.getc.ord # => 1090
2263
+ # f.getc.ord # => 1077
2264
+ # f.getc.ord # => 1089
2265
+ # f.getc.ord # => 1090
2266
+ # f.close
2267
+ #
2268
+ def ungetc: (String object) -> nil
2269
+
2270
+ # <!--
2271
+ # rdoc-file=io.c
2272
+ # - write(*objects) -> integer
2273
+ # -->
2274
+ # Writes each of the given `objects` to `self`, which must be opened for writing
2275
+ # (see [Access Modes](rdoc-ref:File@Access+Modes)); returns the total number
2276
+ # bytes written; each of `objects` that is not a string is converted via method
2277
+ # `to_s`:
2278
+ #
2279
+ # $stdout.write('Hello', ', ', 'World!', "\n") # => 14
2280
+ # $stdout.write('foo', :bar, 2, "\n") # => 8
2281
+ #
2282
+ # Output:
2283
+ #
2284
+ # Hello, World!
2285
+ # foobar2
2286
+ #
2287
+ # Related: IO#read.
2288
+ #
2289
+ def write: (*_ToS string) -> Integer
2290
+
2291
+ # <!--
2292
+ # rdoc-file=io.rb
2293
+ # - ios.write_nonblock(string) -> integer
2294
+ # - ios.write_nonblock(string [, options]) -> integer
2295
+ # -->
2296
+ # Writes the given string to *ios* using the write(2) system call after
2297
+ # O_NONBLOCK is set for the underlying file descriptor.
2298
+ #
2299
+ # It returns the number of bytes written.
2300
+ #
2301
+ # write_nonblock just calls the write(2) system call. It causes all errors the
2302
+ # write(2) system call causes: Errno::EWOULDBLOCK, Errno::EINTR, etc. The result
2303
+ # may also be smaller than string.length (partial write). The caller should care
2304
+ # such errors and partial write.
2305
+ #
2306
+ # If the exception is Errno::EWOULDBLOCK or Errno::EAGAIN, it is extended by
2307
+ # IO::WaitWritable. So IO::WaitWritable can be used to rescue the exceptions for
2308
+ # retrying write_nonblock.
2309
+ #
2310
+ # # Creates a pipe.
2311
+ # r, w = IO.pipe
2312
+ #
2313
+ # # write_nonblock writes only 65536 bytes and return 65536.
2314
+ # # (The pipe size is 65536 bytes on this environment.)
2315
+ # s = "a" * 100000
2316
+ # p w.write_nonblock(s) #=> 65536
2317
+ #
2318
+ # # write_nonblock cannot write a byte and raise EWOULDBLOCK (EAGAIN).
2319
+ # p w.write_nonblock("b") # Resource temporarily unavailable (Errno::EAGAIN)
2320
+ #
2321
+ # If the write buffer is not empty, it is flushed at first.
2322
+ #
2323
+ # When write_nonblock raises an exception kind of IO::WaitWritable,
2324
+ # write_nonblock should not be called until io is writable for avoiding busy
2325
+ # loop. This can be done as follows.
2326
+ #
2327
+ # begin
2328
+ # result = io.write_nonblock(string)
2329
+ # rescue IO::WaitWritable, Errno::EINTR
2330
+ # IO.select(nil, [io])
2331
+ # retry
2332
+ # end
2333
+ #
2334
+ # Note that this doesn't guarantee to write all data in string. The length
2335
+ # written is reported as result and it should be checked later.
2336
+ #
2337
+ # On some platforms such as Windows, write_nonblock is not supported according
2338
+ # to the kind of the IO object. In such cases, write_nonblock raises
2339
+ # <code>Errno::EBADF</code>.
2340
+ #
2341
+ # By specifying a keyword argument *exception* to `false`, you can indicate that
2342
+ # write_nonblock should not raise an IO::WaitWritable exception, but return the
2343
+ # symbol <code>:wait_writable</code> instead.
2344
+ #
2345
+ def write_nonblock: (_ToS s, ?exception: true) -> Integer
2346
+ | (_ToS s, exception: false) -> (Integer | :wait_writable | nil)
2347
+
2348
+ # <!--
2349
+ # rdoc-file=io.c
2350
+ # - IO.binread(path, length = nil, offset = 0) -> string or nil
2351
+ # -->
2352
+ # Behaves like IO.read, except that the stream is opened in binary mode with
2353
+ # ASCII-8BIT encoding.
2354
+ #
2355
+ def self.binread: (path name, ?Integer? length, ?Integer offset) -> String
2356
+
2357
+ # <!--
2358
+ # rdoc-file=io.c
2359
+ # - IO.binwrite(path, string, offset = 0) -> integer
2360
+ # -->
2361
+ # Behaves like IO.write, except that the stream is opened in binary mode with
2362
+ # ASCII-8BIT encoding.
2363
+ #
2364
+ def self.binwrite: (path name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
2365
+
2366
+ # <!--
2367
+ # rdoc-file=io.c
2368
+ # - IO.copy_stream(src, dst, src_length = nil, src_offset = 0) -> integer
2369
+ # -->
2370
+ # Copies from the given `src` to the given `dst`, returning the number of bytes
2371
+ # copied.
2372
+ #
2373
+ # * The given `src` must be one of the following:
2374
+ #
2375
+ # * The path to a readable file, from which source data is to be read.
2376
+ # * An IO-like object, opened for reading and capable of responding to
2377
+ # method <code>:readpartial</code> or method <code>:read</code>.
2378
+ #
2379
+ # * The given `dst` must be one of the following:
2380
+ #
2381
+ # * The path to a writable file, to which data is to be written.
2382
+ # * An IO-like object, opened for writing and capable of responding to
2383
+ # method <code>:write</code>.
2384
+ #
2385
+ # The examples here use file <code>t.txt</code> as source:
2386
+ #
2387
+ # File.read('t.txt')
2388
+ # # => "First line\nSecond line\n\nThird line\nFourth line\n"
2389
+ # File.read('t.txt').size # => 47
2390
+ #
2391
+ # If only arguments `src` and `dst` are given, the entire source stream is
2392
+ # copied:
2393
+ #
2394
+ # # Paths.
2395
+ # IO.copy_stream('t.txt', 't.tmp') # => 47
2396
+ #
2397
+ # # IOs (recall that a File is also an IO).
2398
+ # src_io = File.open('t.txt', 'r') # => #<File:t.txt>
2399
+ # dst_io = File.open('t.tmp', 'w') # => #<File:t.tmp>
2400
+ # IO.copy_stream(src_io, dst_io) # => 47
2401
+ # src_io.close
2402
+ # dst_io.close
2403
+ #
2404
+ # With argument `src_length` a non-negative integer, no more than that many
2405
+ # bytes are copied:
2406
+ #
2407
+ # IO.copy_stream('t.txt', 't.tmp', 10) # => 10
2408
+ # File.read('t.tmp') # => "First line"
2409
+ #
2410
+ # With argument `src_offset` also given, the source stream is read beginning at
2411
+ # that offset:
2412
+ #
2413
+ # IO.copy_stream('t.txt', 't.tmp', 11, 11) # => 11
2414
+ # IO.read('t.tmp') # => "Second line"
2415
+ #
2416
+ def self.copy_stream: (String | _Reader | _ReaderPartial src, String | _Writer dst, ?Integer? copy_length, ?Integer src_offset) -> Integer
2417
+
2418
+ # <!--
2419
+ # rdoc-file=io.c
2420
+ # - IO.popen(env = {}, cmd, mode = 'r', **opts) -> io
2421
+ # - IO.popen(env = {}, cmd, mode = 'r', **opts) {|io| ... } -> object
2422
+ # -->
2423
+ # Executes the given command `cmd` as a subprocess whose $stdin and $stdout are
2424
+ # connected to a new stream `io`.
2425
+ #
2426
+ # This method has potential security vulnerabilities if called with untrusted
2427
+ # input; see [Command Injection](rdoc-ref:security/command_injection.rdoc).
2428
+ #
2429
+ # If no block is given, returns the new stream, which depending on given `mode`
2430
+ # may be open for reading, writing, or both. The stream should be explicitly
2431
+ # closed (eventually) to avoid resource leaks.
2432
+ #
2433
+ # If a block is given, the stream is passed to the block (again, open for
2434
+ # reading, writing, or both); when the block exits, the stream is closed, the
2435
+ # block's value is returned, and the global variable <code>$?</code> is set to
2436
+ # the child's exit status.
2437
+ #
2438
+ # Optional argument `mode` may be any valid IO mode. See [Access
2439
+ # Modes](rdoc-ref:File@Access+Modes).
2440
+ #
2441
+ # Required argument `cmd` determines which of the following occurs:
2442
+ #
2443
+ # * The process forks.
2444
+ # * A specified program runs in a shell.
2445
+ # * A specified program runs with specified arguments.
2446
+ # * A specified program runs with specified arguments and a specified `argv0`.
2447
+ #
2448
+ # Each of these is detailed below.
2449
+ #
2450
+ # The optional hash argument `env` specifies name/value pairs that are to be
2451
+ # added to the environment variables for the subprocess:
2452
+ #
2453
+ # IO.popen({'FOO' => 'bar'}, 'ruby', 'r+') do |pipe|
2454
+ # pipe.puts 'puts ENV["FOO"]'
2455
+ # pipe.close_write
2456
+ # pipe.gets
2457
+ # end => "bar\n"
2458
+ #
2459
+ # Optional keyword arguments `opts` specify:
2460
+ #
2461
+ # * [Open options](rdoc-ref:IO@Open+Options).
2462
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2463
+ # * Options for Kernel#spawn.
2464
+ #
2465
+ # **Forked Process**
2466
+ #
2467
+ # When argument `cmd` is the 1-character string <code>'-'</code>, causes the
2468
+ # process to fork:
2469
+ # IO.popen('-') do |pipe|
2470
+ # if pipe
2471
+ # $stderr.puts "In parent, child pid is #{pipe.pid}\n"
2472
+ # else
2473
+ # $stderr.puts "In child, pid is #{$$}\n"
2474
+ # end
2475
+ # end
2476
+ #
2477
+ # Output:
2478
+ #
2479
+ # In parent, child pid is 26253
2480
+ # In child, pid is 26253
2481
+ #
2482
+ # Note that this is not supported on all platforms.
2483
+ #
2484
+ # **Shell Subprocess**
2485
+ #
2486
+ # When argument `cmd` is a single string (but not <code>'-'</code>), the program
2487
+ # named `cmd` is run as a shell command:
2488
+ #
2489
+ # IO.popen('uname') do |pipe|
2490
+ # pipe.readlines
2491
+ # end
2492
+ #
2493
+ # Output:
2494
+ #
2495
+ # ["Linux\n"]
2496
+ #
2497
+ # Another example:
2498
+ #
2499
+ # IO.popen('/bin/sh', 'r+') do |pipe|
2500
+ # pipe.puts('ls')
2501
+ # pipe.close_write
2502
+ # $stderr.puts pipe.readlines.size
2503
+ # end
2504
+ #
2505
+ # Output:
2506
+ #
2507
+ # 213
2508
+ #
2509
+ # **Program Subprocess**
2510
+ #
2511
+ # When argument `cmd` is an array of strings, the program named
2512
+ # <code>cmd[0]</code> is run with all elements of `cmd` as its arguments:
2513
+ #
2514
+ # IO.popen(['du', '..', '.']) do |pipe|
2515
+ # $stderr.puts pipe.readlines.size
2516
+ # end
2517
+ #
2518
+ # Output:
2519
+ #
2520
+ # 1111
2521
+ #
2522
+ # <strong>Program Subprocess with `argv0`</strong>
2523
+ #
2524
+ # When argument `cmd` is an array whose first element is a 2-element string
2525
+ # array and whose remaining elements (if any) are strings:
2526
+ #
2527
+ # * <code>cmd[0][0]</code> (the first string in the nested array) is the name
2528
+ # of a program that is run.
2529
+ # * <code>cmd[0][1]</code> (the second string in the nested array) is set as
2530
+ # the program's <code>argv[0]</code>.
2531
+ # * <code>cmd[1..-1]</code> (the strings in the outer array) are the program's
2532
+ # arguments.
2533
+ #
2534
+ # Example (sets <code>$0</code> to 'foo'):
2535
+ #
2536
+ # IO.popen([['/bin/sh', 'foo'], '-c', 'echo $0']).read # => "foo\n"
2537
+ #
2538
+ # **Some Special Examples**
2539
+ #
2540
+ # # Set IO encoding.
2541
+ # IO.popen("nkf -e filename", :external_encoding=>"EUC-JP") {|nkf_io|
2542
+ # euc_jp_string = nkf_io.read
2543
+ # }
2544
+ #
2545
+ # # Merge standard output and standard error using Kernel#spawn option. See Kernel#spawn.
2546
+ # IO.popen(["ls", "/", :err=>[:child, :out]]) do |io|
2547
+ # ls_result_with_error = io.read
2548
+ # end
2549
+ #
2550
+ # # Use mixture of spawn options and IO options.
2551
+ # IO.popen(["ls", "/"], :err=>[:child, :out]) do |io|
2552
+ # ls_result_with_error = io.read
2553
+ # end
2554
+ #
2555
+ # f = IO.popen("uname")
2556
+ # p f.readlines
2557
+ # f.close
2558
+ # puts "Parent is #{Process.pid}"
2559
+ # IO.popen("date") {|f| puts f.gets }
2560
+ # IO.popen("-") {|f| $stderr.puts "#{Process.pid} is here, f is #{f.inspect}"}
2561
+ # p $?
2562
+ # IO.popen(%w"sed -e s|^|<foo>| -e s&$&;zot;&", "r+") {|f|
2563
+ # f.puts "bar"; f.close_write; puts f.gets
2564
+ # }
2565
+ #
2566
+ # Output (from last section):
2567
+ #
2568
+ # ["Linux\n"]
2569
+ # Parent is 21346
2570
+ # Thu Jan 15 22:41:19 JST 2009
2571
+ # 21346 is here, f is #<IO:fd 3>
2572
+ # 21352 is here, f is nil
2573
+ # #<Process::Status: pid 21352 exit 0>
2574
+ # <foo>bar;zot;
2575
+ #
2576
+ # Raises exceptions that IO.pipe and Kernel.spawn raise.
2577
+ #
2578
+ def self.popen: (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) -> instance
2579
+ | (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) -> instance
2580
+ | [X] (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) { (instance) -> X } -> X
2581
+ | [X] (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) { (instance) -> X } -> X
2582
+
2583
+ # The command can be given as:
2584
+ #
2585
+ # * Array of string `["ruby", "-v"]`, or
2586
+ # * Array of string with the first element of array `[["ruby", "RUBY"], "-v"]`
2587
+ #
2588
+ # But RBS cannot define such a type. So this is simply a union of `string` or `[String, String]`.
2589
+ #
2590
+ type cmd_array = array[string | [String, String]]
2591
+
2592
+ # <!--
2593
+ # rdoc-file=io.c
2594
+ # - IO.foreach(path, sep = $/, **opts) {|line| block } -> nil
2595
+ # - IO.foreach(path, limit, **opts) {|line| block } -> nil
2596
+ # - IO.foreach(path, sep, limit, **opts) {|line| block } -> nil
2597
+ # - IO.foreach(...) -> an_enumerator
2598
+ # -->
2599
+ # Calls the block with each successive line read from the stream.
2600
+ #
2601
+ # The first argument must be a string that is the path to a file.
2602
+ #
2603
+ # With only argument `path` given, parses lines from the file at the given
2604
+ # `path`, as determined by the default line separator, and calls the block with
2605
+ # each successive line:
2606
+ #
2607
+ # File.foreach('t.txt') {|line| p line }
2608
+ #
2609
+ # Output: the same as above.
2610
+ #
2611
+ # For both forms, command and path, the remaining arguments are the same.
2612
+ #
2613
+ # With argument `sep` given, parses lines as determined by that line separator
2614
+ # (see [Line Separator](rdoc-ref:IO@Line+Separator)):
2615
+ #
2616
+ # File.foreach('t.txt', 'li') {|line| p line }
2617
+ #
2618
+ # Output:
2619
+ #
2620
+ # "First li"
2621
+ # "ne\nSecond li"
2622
+ # "ne\n\nThird li"
2623
+ # "ne\nFourth li"
2624
+ # "ne\n"
2625
+ #
2626
+ # Each paragraph:
2627
+ #
2628
+ # File.foreach('t.txt', '') {|paragraph| p paragraph }
2629
+ #
2630
+ # Output:
2631
+ #
2632
+ # "First line\nSecond line\n\n"
2633
+ # "Third line\nFourth line\n"
2634
+ #
2635
+ # With argument `limit` given, parses lines as determined by the default line
2636
+ # separator and the given line-length limit (see [Line
2637
+ # Separator](rdoc-ref:IO@Line+Separator) and [Line
2638
+ # Limit](rdoc-ref:IO@Line+Limit)):
2639
+ #
2640
+ # File.foreach('t.txt', 7) {|line| p line }
2641
+ #
2642
+ # Output:
2643
+ #
2644
+ # "First l"
2645
+ # "ine\n"
2646
+ # "Second "
2647
+ # "line\n"
2648
+ # "\n"
2649
+ # "Third l"
2650
+ # "ine\n"
2651
+ # "Fourth l"
2652
+ # "line\n"
2653
+ #
2654
+ # With arguments `sep` and `limit` given, combines the two behaviors (see [Line
2655
+ # Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
2656
+ #
2657
+ # Optional keyword arguments `opts` specify:
2658
+ #
2659
+ # * [Open Options](rdoc-ref:IO@Open+Options).
2660
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2661
+ # * [Line Options](rdoc-ref:IO@Line+IO).
2662
+ #
2663
+ # Returns an Enumerator if no block is given.
2664
+ #
2665
+ def self.foreach: (path path, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) { (String line) -> void } -> nil
2666
+ | (path path, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> ::Enumerator[String, nil]
2667
+
2668
+ # <!--
2669
+ # rdoc-file=io.c
2670
+ # - IO.pipe(**opts) -> [read_io, write_io]
2671
+ # - IO.pipe(enc, **opts) -> [read_io, write_io]
2672
+ # - IO.pipe(ext_enc, int_enc, **opts) -> [read_io, write_io]
2673
+ # - IO.pipe(**opts) {|read_io, write_io| ...} -> object
2674
+ # - IO.pipe(enc, **opts) {|read_io, write_io| ...} -> object
2675
+ # - IO.pipe(ext_enc, int_enc, **opts) {|read_io, write_io| ...} -> object
2676
+ # -->
2677
+ # Creates a pair of pipe endpoints, `read_io` and `write_io`, connected to each
2678
+ # other.
2679
+ #
2680
+ # If argument `enc_string` is given, it must be a string containing one of:
2681
+ #
2682
+ # * The name of the encoding to be used as the external encoding.
2683
+ # * The colon-separated names of two encodings to be used as the external and
2684
+ # internal encodings.
2685
+ #
2686
+ # If argument `int_enc` is given, it must be an Encoding object or encoding name
2687
+ # string that specifies the internal encoding to be used; if argument `ext_enc`
2688
+ # is also given, it must be an Encoding object or encoding name string that
2689
+ # specifies the external encoding to be used.
2690
+ #
2691
+ # The string read from `read_io` is tagged with the external encoding; if an
2692
+ # internal encoding is also specified, the string is converted to, and tagged
2693
+ # with, that encoding.
2694
+ #
2695
+ # If any encoding is specified, optional hash arguments specify the conversion
2696
+ # option.
2697
+ #
2698
+ # Optional keyword arguments `opts` specify:
2699
+ #
2700
+ # * [Open Options](rdoc-ref:IO@Open+Options).
2701
+ # * [Encoding Options](rdoc-ref:encodings.rdoc@Encoding+Options).
2702
+ #
2703
+ # With no block given, returns the two endpoints in an array:
2704
+ #
2705
+ # IO.pipe # => [#<IO:fd 4>, #<IO:fd 5>]
2706
+ #
2707
+ # With a block given, calls the block with the two endpoints; closes both
2708
+ # endpoints and returns the value of the block:
2709
+ #
2710
+ # IO.pipe {|read_io, write_io| p read_io; p write_io }
2711
+ #
2712
+ # Output:
2713
+ #
2714
+ # #<IO:fd 6>
2715
+ # #<IO:fd 7>
2716
+ #
2717
+ # Not available on all platforms.
2718
+ #
2719
+ # In the example below, the two processes close the ends of the pipe that they
2720
+ # are not using. This is not just a cosmetic nicety. The read end of a pipe will
2721
+ # not generate an end of file condition if there are any writers with the pipe
2722
+ # still open. In the case of the parent process, the <code>rd.read</code> will
2723
+ # never return if it does not first issue a <code>wr.close</code>:
2724
+ #
2725
+ # rd, wr = IO.pipe
2726
+ #
2727
+ # if fork
2728
+ # wr.close
2729
+ # puts "Parent got: <#{rd.read}>"
2730
+ # rd.close
2731
+ # Process.wait
2732
+ # else
2733
+ # rd.close
2734
+ # puts 'Sending message to parent'
2735
+ # wr.write "Hi Dad"
2736
+ # wr.close
2737
+ # end
2738
+ #
2739
+ # <em>produces:</em>
2740
+ #
2741
+ # Sending message to parent
2742
+ # Parent got: <Hi Dad>
2743
+ #
2744
+ def self.pipe: (?String | Encoding | nil ext_or_ext_int_enc, ?String | Encoding | nil int_enc, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> [IO, IO]
2745
+ | [X] (?String | Encoding | nil ext_or_ext_int_enc, ?String | Encoding | nil int_enc, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) { (IO read_io, IO write_io) -> X } -> X
2746
+
2747
+ # <!--
2748
+ # rdoc-file=io.c
2749
+ # - IO.read(path, length = nil, offset = 0, **opts) -> string or nil
2750
+ # -->
2751
+ # Opens the stream, reads and returns some or all of its content, and closes the
2752
+ # stream; returns `nil` if no bytes were read.
2753
+ #
2754
+ # The first argument must be a string that is the path to a file.
2755
+ #
2756
+ # With only argument `path` given, reads in text mode and returns the entire
2757
+ # content of the file at the given path:
2758
+ #
2759
+ # IO.read('t.txt')
2760
+ # # => "First line\nSecond line\n\nThird line\nFourth line\n"
2761
+ #
2762
+ # On Windows, text mode can terminate reading and leave bytes in the file unread
2763
+ # when encountering certain special bytes. Consider using IO.binread if all
2764
+ # bytes in the file should be read.
2765
+ #
2766
+ # With argument `length`, returns `length` bytes if available:
2767
+ #
2768
+ # IO.read('t.txt', 7) # => "First l"
2769
+ # IO.read('t.txt', 700)
2770
+ # # => "First line\r\nSecond line\r\n\r\nFourth line\r\nFifth line\r\n"
2771
+ #
2772
+ # With arguments `length` and `offset`, returns `length` bytes if available,
2773
+ # beginning at the given `offset`:
2774
+ #
2775
+ # IO.read('t.txt', 10, 2) # => "rst line\nS"
2776
+ # IO.read('t.txt', 10, 200) # => nil
2777
+ #
2778
+ # Optional keyword arguments `opts` specify:
2779
+ #
2780
+ # * [Open Options](rdoc-ref:IO@Open+Options).
2781
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2782
+ #
2783
+ def self.read: (path name, ?Integer? length, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> String
2784
+
2785
+ # <!--
2786
+ # rdoc-file=io.c
2787
+ # - IO.readlines(path, sep = $/, **opts) -> array
2788
+ # - IO.readlines(path, limit, **opts) -> array
2789
+ # - IO.readlines(path, sep, limit, **opts) -> array
2790
+ # -->
2791
+ # Returns an array of all lines read from the stream.
2792
+ #
2793
+ # The first argument must be a string that is the path to a file.
2794
+ #
2795
+ # With only argument `path` given, parses lines from the file at the given
2796
+ # `path`, as determined by the default line separator, and returns those lines
2797
+ # in an array:
2798
+ #
2799
+ # IO.readlines('t.txt')
2800
+ # # => ["First line\n", "Second line\n", "\n", "Third line\n", "Fourth line\n"]
2801
+ #
2802
+ # With argument `sep` given, parses lines as determined by that line separator
2803
+ # (see [Line Separator](rdoc-ref:IO@Line+Separator)):
2804
+ #
2805
+ # # Ordinary separator.
2806
+ # IO.readlines('t.txt', 'li')
2807
+ # # =>["First li", "ne\nSecond li", "ne\n\nThird li", "ne\nFourth li", "ne\n"]
2808
+ # # Get-paragraphs separator.
2809
+ # IO.readlines('t.txt', '')
2810
+ # # => ["First line\nSecond line\n\n", "Third line\nFourth line\n"]
2811
+ # # Get-all separator.
2812
+ # IO.readlines('t.txt', nil)
2813
+ # # => ["First line\nSecond line\n\nThird line\nFourth line\n"]
2814
+ #
2815
+ # With argument `limit` given, parses lines as determined by the default line
2816
+ # separator and the given line-length limit (see [Line
2817
+ # Separator](rdoc-ref:IO@Line+Separator) and [Line
2818
+ # Limit](rdoc-ref:IO@Line+Limit):
2819
+ #
2820
+ # IO.readlines('t.txt', 7)
2821
+ # # => ["First l", "ine\n", "Second ", "line\n", "\n", "Third l", "ine\n", "Fourth ", "line\n"]
2822
+ #
2823
+ # With arguments `sep` and `limit` given, combines the two behaviors (see [Line
2824
+ # Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
2825
+ #
2826
+ # Optional keyword arguments `opts` specify:
2827
+ #
2828
+ # * [Open Options](rdoc-ref:IO@Open+Options).
2829
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2830
+ # * [Line Options](rdoc-ref:IO@Line+IO).
2831
+ #
2832
+ def self.readlines: (path name, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> ::Array[String]
2833
+
2834
+ # <!--
2835
+ # rdoc-file=io.c
2836
+ # - IO.select(read_ios, write_ios = [], error_ios = [], timeout = nil) -> array or nil
2837
+ # -->
2838
+ # Invokes system call [select(2)](https://linux.die.net/man/2/select), which
2839
+ # monitors multiple file descriptors, waiting until one or more of the file
2840
+ # descriptors becomes ready for some class of I/O operation.
2841
+ #
2842
+ # Not implemented on all platforms.
2843
+ #
2844
+ # Each of the arguments `read_ios`, `write_ios`, and `error_ios` is an array of
2845
+ # IO objects.
2846
+ #
2847
+ # Argument `timeout` is a numeric value (such as integer or float) timeout
2848
+ # interval in seconds. `timeout` can also be `nil` or
2849
+ # <code>Float::INFINITY</code>. `nil` and <code>Float::INFINITY</code> means no
2850
+ # timeout.
2851
+ #
2852
+ # The method monitors the IO objects given in all three arrays, waiting for some
2853
+ # to be ready; returns a 3-element array whose elements are:
2854
+ #
2855
+ # * An array of the objects in `read_ios` that are ready for reading.
2856
+ # * An array of the objects in `write_ios` that are ready for writing.
2857
+ # * An array of the objects in `error_ios` have pending exceptions.
2858
+ #
2859
+ # If no object becomes ready within the given `timeout`, `nil` is returned.
2860
+ #
2861
+ # IO.select peeks the buffer of IO objects for testing readability. If the IO
2862
+ # buffer is not empty, IO.select immediately notifies readability. This "peek"
2863
+ # only happens for IO objects. It does not happen for IO-like objects such as
2864
+ # OpenSSL::SSL::SSLSocket.
2865
+ #
2866
+ # The best way to use IO.select is invoking it after non-blocking methods such
2867
+ # as #read_nonblock, #write_nonblock, etc. The methods raise an exception which
2868
+ # is extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
2869
+ # the caller should wait with IO.select. If IO::WaitReadable is raised, the
2870
+ # caller should wait for reading. If IO::WaitWritable is raised, the caller
2871
+ # should wait for writing.
2872
+ #
2873
+ # So, blocking read (#readpartial) can be emulated using #read_nonblock and
2874
+ # IO.select as follows:
2875
+ #
2876
+ # begin
2877
+ # result = io_like.read_nonblock(maxlen)
2878
+ # rescue IO::WaitReadable
2879
+ # IO.select([io_like])
2880
+ # retry
2881
+ # rescue IO::WaitWritable
2882
+ # IO.select(nil, [io_like])
2883
+ # retry
2884
+ # end
2885
+ #
2886
+ # Especially, the combination of non-blocking methods and IO.select is preferred
2887
+ # for IO like objects such as OpenSSL::SSL::SSLSocket. It has #to_io method to
2888
+ # return underlying IO object. IO.select calls #to_io to obtain the file
2889
+ # descriptor to wait.
2890
+ #
2891
+ # This means that readability notified by IO.select doesn't mean readability
2892
+ # from OpenSSL::SSL::SSLSocket object.
2893
+ #
2894
+ # The most likely situation is that OpenSSL::SSL::SSLSocket buffers some data.
2895
+ # IO.select doesn't see the buffer. So IO.select can block when
2896
+ # OpenSSL::SSL::SSLSocket#readpartial doesn't block.
2897
+ #
2898
+ # However, several more complicated situations exist.
2899
+ #
2900
+ # SSL is a protocol which is sequence of records. The record consists of
2901
+ # multiple bytes. So, the remote side of SSL sends a partial record, IO.select
2902
+ # notifies readability but OpenSSL::SSL::SSLSocket cannot decrypt a byte and
2903
+ # OpenSSL::SSL::SSLSocket#readpartial will block.
2904
+ #
2905
+ # Also, the remote side can request SSL renegotiation which forces the local SSL
2906
+ # engine to write some data. This means OpenSSL::SSL::SSLSocket#readpartial may
2907
+ # invoke #write system call and it can block. In such a situation,
2908
+ # OpenSSL::SSL::SSLSocket#read_nonblock raises IO::WaitWritable instead of
2909
+ # blocking. So, the caller should wait for ready for writability as above
2910
+ # example.
2911
+ #
2912
+ # The combination of non-blocking methods and IO.select is also useful for
2913
+ # streams such as tty, pipe socket socket when multiple processes read from a
2914
+ # stream.
2915
+ #
2916
+ # Finally, Linux kernel developers don't guarantee that readability of select(2)
2917
+ # means readability of following read(2) even for a single process; see
2918
+ # [select(2)](https://linux.die.net/man/2/select)
2919
+ #
2920
+ # Invoking IO.select before IO#readpartial works well as usual. However it is
2921
+ # not the best way to use IO.select.
2922
+ #
2923
+ # The writability notified by select(2) doesn't show how many bytes are
2924
+ # writable. IO#write method blocks until given whole string is written. So,
2925
+ # <code>IO#write(two or more bytes)</code> can block after writability is
2926
+ # notified by IO.select. IO#write_nonblock is required to avoid the blocking.
2927
+ #
2928
+ # Blocking write (#write) can be emulated using #write_nonblock and IO.select as
2929
+ # follows: IO::WaitReadable should also be rescued for SSL renegotiation in
2930
+ # OpenSSL::SSL::SSLSocket.
2931
+ #
2932
+ # while 0 < string.bytesize
2933
+ # begin
2934
+ # written = io_like.write_nonblock(string)
2935
+ # rescue IO::WaitReadable
2936
+ # IO.select([io_like])
2937
+ # retry
2938
+ # rescue IO::WaitWritable
2939
+ # IO.select(nil, [io_like])
2940
+ # retry
2941
+ # end
2942
+ # string = string.byteslice(written..-1)
2943
+ # end
2944
+ #
2945
+ # Example:
2946
+ #
2947
+ # rp, wp = IO.pipe
2948
+ # mesg = "ping "
2949
+ # 100.times {
2950
+ # # IO.select follows IO#read. Not the best way to use IO.select.
2951
+ # rs, ws, = IO.select([rp], [wp])
2952
+ # if r = rs[0]
2953
+ # ret = r.read(5)
2954
+ # print ret
2955
+ # case ret
2956
+ # when /ping/
2957
+ # mesg = "pong\n"
2958
+ # when /pong/
2959
+ # mesg = "ping "
2960
+ # end
2961
+ # end
2962
+ # if w = ws[0]
2963
+ # w.write(mesg)
2964
+ # end
2965
+ # }
2966
+ #
2967
+ # Output:
2968
+ #
2969
+ # ping pong
2970
+ # ping pong
2971
+ # ping pong
2972
+ # (snipped)
2973
+ # ping
2974
+ #
2975
+ def self.select: [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array) -> [ Array[X], Array[Y], Array[Z] ]
2976
+ | [X, Y, Z] (::Array[X & io]? read_array, ?::Array[Y & io]? write_array, ?::Array[Z & io]? error_array, Time::_Timeout? timeout) -> [ Array[X], Array[Y], Array[Z] ]?
2977
+
2978
+ # <!--
2979
+ # rdoc-file=io.c
2980
+ # - IO.sysopen(path, mode = 'r', perm = 0666) -> integer
2981
+ # -->
2982
+ # Opens the file at the given path with the given mode and permissions; returns
2983
+ # the integer file descriptor.
2984
+ #
2985
+ # If the file is to be readable, it must exist; if the file is to be writable
2986
+ # and does not exist, it is created with the given permissions:
2987
+ #
2988
+ # File.write('t.tmp', '') # => 0
2989
+ # IO.sysopen('t.tmp') # => 8
2990
+ # IO.sysopen('t.tmp', 'w') # => 9
2991
+ #
2992
+ def self.sysopen: (String path, ?String mode, ?String perm) -> Integer
2993
+
2994
+ # <!--
2995
+ # rdoc-file=io.c
2996
+ # - IO.try_convert(object) -> new_io or nil
2997
+ # -->
2998
+ # Attempts to convert `object` into an IO object via method `to_io`; returns the
2999
+ # new IO object if successful, or `nil` otherwise:
3000
+ #
3001
+ # IO.try_convert(STDOUT) # => #<IO:<STDOUT>>
3002
+ # IO.try_convert(ARGF) # => #<IO:<STDIN>>
3003
+ # IO.try_convert('STDOUT') # => nil
3004
+ #
3005
+ def self.try_convert: (_ToIO obj) -> IO
3006
+ | (untyped obj) -> IO?
3007
+
3008
+ # <!--
3009
+ # rdoc-file=io.c
3010
+ # - IO.write(path, data, offset = 0, **opts) -> integer
3011
+ # -->
3012
+ # Opens the stream, writes the given `data` to it, and closes the stream;
3013
+ # returns the number of bytes written.
3014
+ #
3015
+ # The first argument must be a string that is the path to a file.
3016
+ #
3017
+ # With only argument `path` given, writes the given `data` to the file at that
3018
+ # path:
3019
+ #
3020
+ # IO.write('t.tmp', 'abc') # => 3
3021
+ # File.read('t.tmp') # => "abc"
3022
+ #
3023
+ # If `offset` is zero (the default), the file is overwritten:
3024
+ #
3025
+ # IO.write('t.tmp', 'A') # => 1
3026
+ # File.read('t.tmp') # => "A"
3027
+ #
3028
+ # If `offset` in within the file content, the file is partly overwritten:
3029
+ #
3030
+ # IO.write('t.tmp', 'abcdef') # => 3
3031
+ # File.read('t.tmp') # => "abcdef"
3032
+ # # Offset within content.
3033
+ # IO.write('t.tmp', '012', 2) # => 3
3034
+ # File.read('t.tmp') # => "ab012f"
3035
+ #
3036
+ # If `offset` is outside the file content, the file is padded with null
3037
+ # characters <code>"\u0000"</code>:
3038
+ #
3039
+ # IO.write('t.tmp', 'xyz', 10) # => 3
3040
+ # File.read('t.tmp') # => "ab012f\u0000\u0000\u0000\u0000xyz"
3041
+ #
3042
+ # Optional keyword arguments `opts` specify:
3043
+ #
3044
+ # * [Open Options](rdoc-ref:IO@Open+Options).
3045
+ # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
3046
+ #
3047
+ def self.write: (path path, _ToS data, ?Integer offset, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> Integer
3048
+
3049
+ # <!--
3050
+ # rdoc-file=io.c
3051
+ # - IO.for_fd(fd, mode = 'r', **opts) -> io
3052
+ # -->
3053
+ # Synonym for IO.new.
3054
+ #
3055
+ alias self.for_fd self.new
3056
+
3057
+ # <!--
3058
+ # rdoc-file=io.c
3059
+ # - IO.open(fd, mode = 'r', **opts) -> io
3060
+ # - IO.open(fd, mode = 'r', **opts) {|io| ... } -> object
3061
+ # -->
3062
+ # Creates a new IO object, via IO.new with the given arguments.
3063
+ #
3064
+ # With no block given, returns the IO object.
3065
+ #
3066
+ # With a block given, calls the block with the IO object and returns the block's
3067
+ # value.
3068
+ #
3069
+ def self.open: (int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) -> instance
3070
+ | [X] (int fd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String) { (instance) -> X } -> X
3071
+
3072
+ # <!-- rdoc-file=io.c -->
3073
+ # Calls the block with each remaining line read from the stream; returns `self`.
3074
+ # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
3075
+ #
3076
+ # With no arguments given, reads lines as determined by line separator
3077
+ # <code>$/</code>:
3078
+ #
3079
+ # f = File.new('t.txt')
3080
+ # f.each_line {|line| p line }
3081
+ # f.each_line {|line| fail 'Cannot happen' }
3082
+ # f.close
3083
+ #
3084
+ # Output:
3085
+ #
3086
+ # "First line\n"
3087
+ # "Second line\n"
3088
+ # "\n"
3089
+ # "Fourth line\n"
3090
+ # "Fifth line\n"
3091
+ #
3092
+ # With only string argument `sep` given, reads lines as determined by line
3093
+ # separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator):
3094
+ #
3095
+ # f = File.new('t.txt')
3096
+ # f.each_line('li') {|line| p line }
3097
+ # f.close
3098
+ #
3099
+ # Output:
3100
+ #
3101
+ # "First li"
3102
+ # "ne\nSecond li"
3103
+ # "ne\n\nFourth li"
3104
+ # "ne\nFifth li"
3105
+ # "ne\n"
3106
+ #
3107
+ # The two special values for `sep` are honored:
3108
+ #
3109
+ # f = File.new('t.txt')
3110
+ # # Get all into one string.
3111
+ # f.each_line(nil) {|line| p line }
3112
+ # f.close
3113
+ #
3114
+ # Output:
3115
+ #
3116
+ # "First line\nSecond line\n\nFourth line\nFifth line\n"
3117
+ #
3118
+ # f.rewind
3119
+ # # Get paragraphs (up to two line separators).
3120
+ # f.each_line('') {|line| p line }
3121
+ #
3122
+ # Output:
3123
+ #
3124
+ # "First line\nSecond line\n\n"
3125
+ # "Fourth line\nFifth line\n"
3126
+ #
3127
+ # With only integer argument `limit` given, limits the number of bytes in each
3128
+ # line; see [Line Limit](rdoc-ref:IO@Line+Limit):
3129
+ #
3130
+ # f = File.new('t.txt')
3131
+ # f.each_line(8) {|line| p line }
3132
+ # f.close
3133
+ #
3134
+ # Output:
3135
+ #
3136
+ # "First li"
3137
+ # "ne\n"
3138
+ # "Second l"
3139
+ # "ine\n"
3140
+ # "\n"
3141
+ # "Fourth l"
3142
+ # "ine\n"
3143
+ # "Fifth li"
3144
+ # "ne\n"
3145
+ #
3146
+ # With arguments `sep` and `limit` given, combines the two behaviors (see [Line
3147
+ # Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
3148
+ #
3149
+ # Optional keyword argument `chomp` specifies whether line separators are to be
3150
+ # omitted:
3151
+ #
3152
+ # f = File.new('t.txt')
3153
+ # f.each_line(chomp: true) {|line| p line }
3154
+ # f.close
3155
+ #
3156
+ # Output:
3157
+ #
3158
+ # "First line"
3159
+ # "Second line"
3160
+ # ""
3161
+ # "Fourth line"
3162
+ # "Fifth line"
3163
+ #
3164
+ # Returns an Enumerator if no block is given.
3165
+ #
3166
+ def each_line: (?string sep, ?int limit, ?chomp: boolish) { (String line) -> void } -> self
3167
+ | (?string sep, ?int limit, ?chomp: boolish) -> ::Enumerator[String, self]
3168
+
3169
+ # <!--
3170
+ # rdoc-file=io.c
3171
+ # - each_line(sep = $/, chomp: false) {|line| ... } -> self
3172
+ # - each_line(limit, chomp: false) {|line| ... } -> self
3173
+ # - each_line(sep, limit, chomp: false) {|line| ... } -> self
3174
+ # - each_line -> enumerator
3175
+ # -->
3176
+ # Calls the block with each remaining line read from the stream; returns `self`.
3177
+ # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
3178
+ #
3179
+ # With no arguments given, reads lines as determined by line separator
3180
+ # <code>$/</code>:
3181
+ #
3182
+ # f = File.new('t.txt')
3183
+ # f.each_line {|line| p line }
3184
+ # f.each_line {|line| fail 'Cannot happen' }
3185
+ # f.close
3186
+ #
3187
+ # Output:
3188
+ #
3189
+ # "First line\n"
3190
+ # "Second line\n"
3191
+ # "\n"
3192
+ # "Fourth line\n"
3193
+ # "Fifth line\n"
3194
+ #
3195
+ # With only string argument `sep` given, reads lines as determined by line
3196
+ # separator `sep`; see [Line Separator](rdoc-ref:IO@Line+Separator):
3197
+ #
3198
+ # f = File.new('t.txt')
3199
+ # f.each_line('li') {|line| p line }
3200
+ # f.close
3201
+ #
3202
+ # Output:
3203
+ #
3204
+ # "First li"
3205
+ # "ne\nSecond li"
3206
+ # "ne\n\nFourth li"
3207
+ # "ne\nFifth li"
3208
+ # "ne\n"
3209
+ #
3210
+ # The two special values for `sep` are honored:
3211
+ #
3212
+ # f = File.new('t.txt')
3213
+ # # Get all into one string.
3214
+ # f.each_line(nil) {|line| p line }
3215
+ # f.close
3216
+ #
3217
+ # Output:
3218
+ #
3219
+ # "First line\nSecond line\n\nFourth line\nFifth line\n"
3220
+ #
3221
+ # f.rewind
3222
+ # # Get paragraphs (up to two line separators).
3223
+ # f.each_line('') {|line| p line }
3224
+ #
3225
+ # Output:
3226
+ #
3227
+ # "First line\nSecond line\n\n"
3228
+ # "Fourth line\nFifth line\n"
3229
+ #
3230
+ # With only integer argument `limit` given, limits the number of bytes in each
3231
+ # line; see [Line Limit](rdoc-ref:IO@Line+Limit):
3232
+ #
3233
+ # f = File.new('t.txt')
3234
+ # f.each_line(8) {|line| p line }
3235
+ # f.close
3236
+ #
3237
+ # Output:
3238
+ #
3239
+ # "First li"
3240
+ # "ne\n"
3241
+ # "Second l"
3242
+ # "ine\n"
3243
+ # "\n"
3244
+ # "Fourth l"
3245
+ # "ine\n"
3246
+ # "Fifth li"
3247
+ # "ne\n"
3248
+ #
3249
+ # With arguments `sep` and `limit` given, combines the two behaviors (see [Line
3250
+ # Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit)).
3251
+ #
3252
+ # Optional keyword argument `chomp` specifies whether line separators are to be
3253
+ # omitted:
3254
+ #
3255
+ # f = File.new('t.txt')
3256
+ # f.each_line(chomp: true) {|line| p line }
3257
+ # f.close
3258
+ #
3259
+ # Output:
3260
+ #
3261
+ # "First line"
3262
+ # "Second line"
3263
+ # ""
3264
+ # "Fourth line"
3265
+ # "Fifth line"
3266
+ #
3267
+ # Returns an Enumerator if no block is given.
3268
+ #
3269
+ alias each each_line
3270
+
3271
+ # <!-- rdoc-file=io.c -->
3272
+ # Returns `true` if the stream is positioned at its end, `false` otherwise; see
3273
+ # [Position](rdoc-ref:IO@Position):
3274
+ #
3275
+ # f = File.open('t.txt')
3276
+ # f.eof # => false
3277
+ # f.seek(0, :END) # => 0
3278
+ # f.eof # => true
3279
+ # f.close
3280
+ #
3281
+ # Raises an exception unless the stream is opened for reading; see
3282
+ # [Mode](rdoc-ref:File@Access+Modes).
3283
+ #
3284
+ # If `self` is a stream such as pipe or socket, this method blocks until the
3285
+ # other end sends some data or closes it:
3286
+ #
3287
+ # r, w = IO.pipe
3288
+ # Thread.new { sleep 1; w.close }
3289
+ # r.eof? # => true # After 1-second wait.
3290
+ #
3291
+ # r, w = IO.pipe
3292
+ # Thread.new { sleep 1; w.puts "a" }
3293
+ # r.eof? # => false # After 1-second wait.
3294
+ #
3295
+ # r, w = IO.pipe
3296
+ # r.eof? # blocks forever
3297
+ #
3298
+ # Note that this method reads data to the input byte buffer. So IO#sysread may
3299
+ # not behave as you intend with IO#eof?, unless you call IO#rewind first (which
3300
+ # is not available for some streams).
3301
+ #
3302
+ alias eof? eof
3303
+
3304
+ # <!-- rdoc-file=io.c -->
3305
+ # Returns the integer file descriptor for the stream:
3306
+ #
3307
+ # $stdin.fileno # => 0
3308
+ # $stdout.fileno # => 1
3309
+ # $stderr.fileno # => 2
3310
+ # File.open('t.txt').fileno # => 10
3311
+ # f.close
3312
+ #
3313
+ alias to_i fileno
3314
+
3315
+ interface _ForFd[RET]
3316
+ def for_fd: (?) -> RET
3317
+ end
3318
+ end
3319
+
3320
+ IO::APPEND: Integer
3321
+
3322
+ IO::BINARY: Integer
3323
+
3324
+ IO::CREAT: Integer
3325
+
3326
+ IO::DIRECT: Integer
3327
+
3328
+ IO::DSYNC: Integer
3329
+
3330
+ IO::EXCL: Integer
3331
+
3332
+ IO::FNM_CASEFOLD: Integer
3333
+
3334
+ IO::FNM_DOTMATCH: Integer
3335
+
3336
+ IO::FNM_EXTGLOB: Integer
3337
+
3338
+ IO::FNM_NOESCAPE: Integer
3339
+
3340
+ IO::FNM_PATHNAME: Integer
3341
+
3342
+ IO::FNM_SHORTNAME: Integer
3343
+
3344
+ IO::FNM_SYSCASE: Integer
3345
+
3346
+ IO::LOCK_EX: Integer
3347
+
3348
+ IO::LOCK_NB: Integer
3349
+
3350
+ IO::LOCK_SH: Integer
3351
+
3352
+ IO::LOCK_UN: Integer
3353
+
3354
+ IO::NOATIME: Integer
3355
+
3356
+ IO::NOCTTY: Integer
3357
+
3358
+ IO::NOFOLLOW: Integer
3359
+
3360
+ IO::NONBLOCK: Integer
3361
+
3362
+ IO::NULL: String
3363
+
3364
+ IO::RDONLY: Integer
3365
+
3366
+ IO::RDWR: Integer
3367
+
3368
+ IO::RSYNC: Integer
3369
+
3370
+ # <!-- rdoc-file=io.c -->
3371
+ # Set I/O position from the current position
3372
+ #
3373
+ IO::SEEK_CUR: Integer
3374
+
3375
+ # <!-- rdoc-file=io.c -->
3376
+ # Set I/O position to the next location containing data
3377
+ #
3378
+ IO::SEEK_DATA: Integer
3379
+
3380
+ # <!-- rdoc-file=io.c -->
3381
+ # Set I/O position from the end
3382
+ #
3383
+ IO::SEEK_END: Integer
3384
+
3385
+ # <!-- rdoc-file=io.c -->
3386
+ # Set I/O position to the next hole
3387
+ #
3388
+ IO::SEEK_HOLE: Integer
3389
+
3390
+ # <!-- rdoc-file=io.c -->
3391
+ # Set I/O position from the beginning
3392
+ #
3393
+ IO::SEEK_SET: Integer
3394
+
3395
+ IO::SHARE_DELETE: Integer
3396
+
3397
+ IO::SYNC: Integer
3398
+
3399
+ IO::TMPFILE: Integer
3400
+
3401
+ IO::TRUNC: Integer
3402
+
3403
+ IO::WRONLY: Integer
3404
+
3405
+ # <!-- rdoc-file=io.c -->
3406
+ # Readable event mask for IO#wait.
3407
+ #
3408
+ IO::READABLE: Integer
3409
+
3410
+ # <!-- rdoc-file=io.c -->
3411
+ # Writable event mask for IO#wait.
3412
+ #
3413
+ IO::WRITABLE: Integer
3414
+
3415
+ # <!-- rdoc-file=io.c -->
3416
+ # Priority event mask for IO#wait.
3417
+ #
3418
+ IO::PRIORITY: Integer
3419
+
3420
+ # <!-- rdoc-file=io.c -->
3421
+ # exception to wait for reading by EAGAIN. see IO.select.
3422
+ #
3423
+ class IO::EAGAINWaitReadable < Errno::EAGAIN
3424
+ include IO::WaitReadable
3425
+ end
3426
+
3427
+ IO::EAGAINWaitReadable::Errno: Integer
3428
+
3429
+ # <!-- rdoc-file=io.c -->
3430
+ # exception to wait for writing by EAGAIN. see IO.select.
3431
+ #
3432
+ class IO::EAGAINWaitWritable < Errno::EAGAIN
3433
+ include IO::WaitWritable
3434
+ end
3435
+
3436
+ IO::EAGAINWaitWritable::Errno: Integer
3437
+
3438
+ # <!-- rdoc-file=io.c -->
3439
+ # exception to wait for reading by EINPROGRESS. see IO.select.
3440
+ #
3441
+ class IO::EINPROGRESSWaitReadable < Errno::EINPROGRESS
3442
+ include IO::WaitReadable
3443
+ end
3444
+
3445
+ IO::EINPROGRESSWaitReadable::Errno: Integer
3446
+
3447
+ # <!-- rdoc-file=io.c -->
3448
+ # exception to wait for writing by EINPROGRESS. see IO.select.
3449
+ #
3450
+ class IO::EINPROGRESSWaitWritable < Errno::EINPROGRESS
3451
+ include IO::WaitWritable
3452
+ end
3453
+
3454
+ IO::EINPROGRESSWaitWritable::Errno: Integer
3455
+
3456
+ # <!-- rdoc-file=io.c -->
3457
+ # exception to wait for reading. see IO.select.
3458
+ #
3459
+ module IO::WaitReadable
3460
+ end
3461
+
3462
+ # <!-- rdoc-file=io.c -->
3463
+ # exception to wait for writing. see IO.select.
3464
+ #
3465
+ module IO::WaitWritable
3466
+ end
3467
+
3468
+ # <!-- rdoc-file=io.c -->
3469
+ # Can be raised by IO operations when IO#timeout= is set.
3470
+ #
3471
+ class IO::TimeoutError < IOError
3472
+ end