rbs 3.9.4 → 4.2.0

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 (354) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +75 -0
  3. data/.clangd +2 -0
  4. data/.dockerignore +37 -0
  5. data/.gitattributes +1 -0
  6. data/.github/dependabot.yml +16 -14
  7. data/.github/workflows/bundle-update.yml +63 -0
  8. data/.github/workflows/c-check.yml +66 -0
  9. data/.github/workflows/changelog.yml +121 -0
  10. data/.github/workflows/comments.yml +6 -4
  11. data/.github/workflows/dependabot.yml +2 -2
  12. data/.github/workflows/jruby.yml +74 -0
  13. data/.github/workflows/release-gems.yml +234 -0
  14. data/.github/workflows/ruby.yml +86 -32
  15. data/.github/workflows/rust.yml +186 -0
  16. data/.github/workflows/truffleruby.yml +54 -0
  17. data/.github/workflows/typecheck.yml +6 -3
  18. data/.github/workflows/wasm.yml +55 -0
  19. data/.github/workflows/windows.yml +10 -4
  20. data/.gitignore +16 -0
  21. data/.rubocop.yml +1 -2
  22. data/CHANGELOG.md +502 -0
  23. data/Dockerfile.jruby +53 -0
  24. data/README.md +42 -5
  25. data/Rakefile +892 -111
  26. data/Steepfile +11 -0
  27. data/config.yml +665 -62
  28. data/core/array.rbs +541 -398
  29. data/core/basic_object.rbs +9 -8
  30. data/core/binding.rbs +0 -2
  31. data/core/builtin.rbs +9 -8
  32. data/core/class.rbs +11 -8
  33. data/core/comparable.rbs +55 -34
  34. data/core/complex.rbs +104 -78
  35. data/core/dir.rbs +61 -49
  36. data/core/encoding.rbs +12 -15
  37. data/core/enumerable.rbs +297 -196
  38. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  39. data/core/enumerator/product.rbs +5 -5
  40. data/core/enumerator.rbs +91 -28
  41. data/core/errno.rbs +11 -2
  42. data/core/errors.rbs +58 -29
  43. data/core/exception.rbs +13 -13
  44. data/core/fiber.rbs +74 -54
  45. data/core/file.rbs +260 -1151
  46. data/core/file_constants.rbs +463 -0
  47. data/core/file_stat.rbs +534 -0
  48. data/core/file_test.rbs +3 -3
  49. data/core/float.rbs +257 -116
  50. data/core/gc.rbs +425 -281
  51. data/core/hash.rbs +1151 -829
  52. data/core/integer.rbs +156 -195
  53. data/core/io/buffer.rbs +53 -42
  54. data/core/io/wait.rbs +13 -35
  55. data/core/io.rbs +222 -155
  56. data/core/kernel.rbs +239 -163
  57. data/core/marshal.rbs +4 -4
  58. data/core/match_data.rbs +16 -14
  59. data/core/math.rbs +107 -66
  60. data/core/method.rbs +69 -33
  61. data/core/module.rbs +302 -150
  62. data/core/nil_class.rbs +7 -6
  63. data/core/numeric.rbs +77 -63
  64. data/core/object.rbs +9 -11
  65. data/core/object_space/weak_key_map.rbs +7 -7
  66. data/core/object_space.rbs +30 -23
  67. data/core/pathname.rbs +1312 -0
  68. data/core/proc.rbs +95 -58
  69. data/core/process.rbs +222 -202
  70. data/core/ractor.rbs +364 -518
  71. data/core/random.rbs +21 -3
  72. data/core/range.rbs +181 -79
  73. data/core/rational.rbs +60 -89
  74. data/core/rbs/ops.rbs +154 -0
  75. data/core/rbs/unnamed/argf.rbs +63 -56
  76. data/core/rbs/unnamed/env_class.rbs +19 -14
  77. data/core/rbs/unnamed/main_class.rbs +123 -0
  78. data/core/rbs/unnamed/random.rbs +11 -118
  79. data/core/regexp.rbs +258 -214
  80. data/core/ruby.rbs +53 -0
  81. data/core/ruby_vm.rbs +78 -34
  82. data/core/rubygems/config_file.rbs +5 -5
  83. data/core/rubygems/errors.rbs +6 -70
  84. data/core/rubygems/requirement.rbs +5 -15
  85. data/core/rubygems/rubygems.rbs +18 -81
  86. data/core/rubygems/specification.rbs +8 -0
  87. data/core/rubygems/version.rbs +2 -163
  88. data/core/set.rbs +493 -363
  89. data/core/signal.rbs +26 -16
  90. data/core/string.rbs +3234 -1285
  91. data/core/struct.rbs +43 -42
  92. data/core/symbol.rbs +41 -34
  93. data/core/thread.rbs +139 -83
  94. data/core/time.rbs +81 -50
  95. data/core/trace_point.rbs +41 -35
  96. data/core/true_class.rbs +2 -2
  97. data/core/unbound_method.rbs +24 -16
  98. data/core/warning.rbs +7 -7
  99. data/docs/CONTRIBUTING.md +3 -2
  100. data/docs/aliases.md +79 -0
  101. data/docs/collection.md +3 -3
  102. data/docs/config.md +171 -0
  103. data/docs/encoding.md +56 -0
  104. data/docs/gem.md +0 -1
  105. data/docs/inline.md +634 -0
  106. data/docs/rbs_by_example.md +20 -20
  107. data/docs/release.md +303 -0
  108. data/docs/rust.md +96 -0
  109. data/docs/sigs.md +3 -3
  110. data/docs/stdlib.md +8 -0
  111. data/docs/syntax.md +60 -18
  112. data/docs/type_fingerprint.md +21 -0
  113. data/docs/wasm_serialization.md +80 -0
  114. data/exe/rbs +1 -1
  115. data/ext/rbs_extension/ast_translation.c +1870 -0
  116. data/ext/rbs_extension/ast_translation.h +41 -0
  117. data/ext/rbs_extension/class_constants.c +189 -0
  118. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +24 -1
  119. data/ext/rbs_extension/compat.h +10 -0
  120. data/ext/rbs_extension/extconf.rb +26 -1
  121. data/ext/rbs_extension/legacy_location.c +299 -0
  122. data/ext/rbs_extension/legacy_location.h +82 -0
  123. data/ext/rbs_extension/main.c +639 -23
  124. data/ext/rbs_extension/rbs_extension.h +6 -21
  125. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  126. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  127. data/include/rbs/ast.h +1055 -0
  128. data/include/rbs/defines.h +104 -0
  129. data/include/rbs/lexer.h +208 -0
  130. data/include/rbs/location.h +40 -0
  131. data/include/rbs/parser.h +187 -0
  132. data/include/rbs/serialize.h +39 -0
  133. data/include/rbs/string.h +47 -0
  134. data/include/rbs/util/rbs_allocator.h +59 -0
  135. data/include/rbs/util/rbs_assert.h +20 -0
  136. data/include/rbs/util/rbs_buffer.h +83 -0
  137. data/include/rbs/util/rbs_constant_pool.h +6 -70
  138. data/include/rbs/util/rbs_encoding.h +282 -0
  139. data/include/rbs/util/rbs_unescape.h +24 -0
  140. data/include/rbs.h +9 -2
  141. data/lib/rbs/annotate/formatter.rb +3 -13
  142. data/lib/rbs/annotate/rdoc_annotator.rb +30 -32
  143. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  144. data/lib/rbs/ast/annotation.rb +1 -1
  145. data/lib/rbs/ast/comment.rb +1 -1
  146. data/lib/rbs/ast/declarations.rb +11 -11
  147. data/lib/rbs/ast/members.rb +14 -14
  148. data/lib/rbs/ast/ruby/annotations.rb +451 -0
  149. data/lib/rbs/ast/ruby/comment_block.rb +247 -0
  150. data/lib/rbs/ast/ruby/declarations.rb +291 -0
  151. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  152. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  153. data/lib/rbs/ast/ruby/members.rb +762 -0
  154. data/lib/rbs/ast/type_param.rb +25 -5
  155. data/lib/rbs/buffer.rb +142 -20
  156. data/lib/rbs/cli/diff.rb +16 -15
  157. data/lib/rbs/cli/validate.rb +63 -126
  158. data/lib/rbs/cli.rb +59 -29
  159. data/lib/rbs/collection/config/lockfile_generator.rb +28 -3
  160. data/lib/rbs/collection/sources/git.rb +7 -0
  161. data/lib/rbs/definition.rb +6 -1
  162. data/lib/rbs/definition_builder/ancestor_builder.rb +129 -70
  163. data/lib/rbs/definition_builder/method_builder.rb +74 -33
  164. data/lib/rbs/definition_builder.rb +181 -21
  165. data/lib/rbs/diff.rb +7 -1
  166. data/lib/rbs/environment/class_entry.rb +81 -0
  167. data/lib/rbs/environment/module_entry.rb +91 -0
  168. data/lib/rbs/environment.rb +410 -215
  169. data/lib/rbs/environment_loader.rb +2 -8
  170. data/lib/rbs/errors.rb +31 -21
  171. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  172. data/lib/rbs/inline_parser.rb +568 -0
  173. data/lib/rbs/location_aux.rb +36 -4
  174. data/lib/rbs/locator.rb +5 -1
  175. data/lib/rbs/method_type.rb +5 -3
  176. data/lib/rbs/namespace.rb +47 -18
  177. data/lib/rbs/parser_aux.rb +37 -7
  178. data/lib/rbs/prototype/helpers.rb +24 -0
  179. data/lib/rbs/prototype/rb.rb +3 -28
  180. data/lib/rbs/prototype/rbi.rb +196 -45
  181. data/lib/rbs/prototype/runtime/value_object_generator.rb +0 -1
  182. data/lib/rbs/prototype/runtime.rb +13 -3
  183. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  184. data/lib/rbs/resolver/type_name_resolver.rb +120 -44
  185. data/lib/rbs/rewriter.rb +70 -0
  186. data/lib/rbs/source.rb +99 -0
  187. data/lib/rbs/subtractor.rb +7 -4
  188. data/lib/rbs/test/type_check.rb +25 -3
  189. data/lib/rbs/type_name.rb +34 -21
  190. data/lib/rbs/types.rb +135 -81
  191. data/lib/rbs/unit_test/convertibles.rb +1 -0
  192. data/lib/rbs/unit_test/type_assertions.rb +47 -11
  193. data/lib/rbs/validator.rb +2 -2
  194. data/lib/rbs/version.rb +1 -1
  195. data/lib/rbs/wasm/deserializer.rb +213 -0
  196. data/lib/rbs/wasm/location.rb +61 -0
  197. data/lib/rbs/wasm/parser.rb +174 -0
  198. data/lib/rbs/wasm/runtime.rb +211 -0
  199. data/lib/rbs/wasm/serialization_schema.rb +111 -0
  200. data/lib/rbs.rb +25 -2
  201. data/lib/rbs_jars.rb +39 -0
  202. data/lib/rdoc/discover.rb +1 -1
  203. data/lib/rdoc_plugin/parser.rb +8 -3
  204. data/rbs.gemspec +34 -6
  205. data/schema/function.json +12 -1
  206. data/schema/typeParam.json +17 -1
  207. data/sig/ancestor_builder.rbs +1 -1
  208. data/sig/annotate/formatter.rbs +2 -2
  209. data/sig/annotate/rdoc_annotater.rbs +13 -10
  210. data/sig/ast/ruby/annotations.rbs +470 -0
  211. data/sig/ast/ruby/comment_block.rbs +127 -0
  212. data/sig/ast/ruby/declarations.rbs +158 -0
  213. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  214. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  215. data/sig/ast/ruby/members.rbs +198 -0
  216. data/sig/buffer.rbs +81 -5
  217. data/sig/cli/diff.rbs +5 -11
  218. data/sig/cli/validate.rbs +12 -8
  219. data/sig/cli.rbs +18 -18
  220. data/sig/collection/config/lockfile_generator.rbs +2 -0
  221. data/sig/definition.rbs +6 -0
  222. data/sig/definition_builder.rbs +3 -1
  223. data/sig/environment/class_entry.rbs +56 -0
  224. data/sig/environment/module_entry.rbs +65 -0
  225. data/sig/environment.rbs +94 -87
  226. data/sig/errors.rbs +26 -20
  227. data/sig/inline_parser/comment_association.rbs +71 -0
  228. data/sig/inline_parser.rbs +126 -0
  229. data/sig/location.rbs +32 -7
  230. data/sig/locator.rbs +0 -2
  231. data/sig/manifest.yaml +0 -2
  232. data/sig/method_builder.rbs +9 -4
  233. data/sig/namespace.rbs +20 -5
  234. data/sig/parser.rbs +79 -15
  235. data/sig/prototype/helpers.rbs +2 -0
  236. data/sig/prototype/rbi.rbs +33 -4
  237. data/sig/resolver/type_name_resolver.rbs +36 -10
  238. data/sig/rewriter.rbs +45 -0
  239. data/sig/source.rbs +48 -0
  240. data/sig/type_param.rbs +13 -8
  241. data/sig/typename.rbs +15 -5
  242. data/sig/types.rbs +21 -9
  243. data/sig/unit_test/spy.rbs +0 -8
  244. data/sig/unit_test/type_assertions.rbs +17 -2
  245. data/sig/wasm/deserializer.rbs +66 -0
  246. data/sig/wasm/serialization_schema.rbs +13 -0
  247. data/src/ast.c +1644 -0
  248. data/src/lexer.c +3223 -0
  249. data/src/lexer.re +187 -0
  250. data/src/lexstate.c +222 -0
  251. data/src/location.c +31 -0
  252. data/src/parser.c +4318 -0
  253. data/src/serialize.c +965 -0
  254. data/src/string.c +41 -0
  255. data/src/util/rbs_allocator.c +171 -0
  256. data/src/util/rbs_assert.c +19 -0
  257. data/src/util/rbs_buffer.c +54 -0
  258. data/src/util/rbs_constant_pool.c +18 -92
  259. data/src/util/rbs_encoding.c +21454 -0
  260. data/src/util/rbs_unescape.c +167 -0
  261. data/stdlib/abbrev/0/array.rbs +1 -1
  262. data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
  263. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  264. data/stdlib/cgi/0/core.rbs +9 -393
  265. data/stdlib/cgi/0/manifest.yaml +1 -0
  266. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  267. data/stdlib/coverage/0/coverage.rbs +7 -4
  268. data/stdlib/csv/0/csv.rbs +5 -5
  269. data/stdlib/date/0/date.rbs +92 -79
  270. data/stdlib/date/0/date_time.rbs +25 -24
  271. data/stdlib/delegate/0/delegator.rbs +11 -7
  272. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  273. data/stdlib/digest/0/digest.rbs +117 -1
  274. data/stdlib/erb/0/erb.rbs +754 -353
  275. data/stdlib/etc/0/etc.rbs +73 -54
  276. data/stdlib/fileutils/0/fileutils.rbs +179 -160
  277. data/stdlib/forwardable/0/forwardable.rbs +13 -10
  278. data/stdlib/io-console/0/io-console.rbs +2 -2
  279. data/stdlib/ipaddr/0/ipaddr.rbs +0 -5
  280. data/stdlib/json/0/json.rbs +232 -185
  281. data/stdlib/monitor/0/monitor.rbs +9 -9
  282. data/stdlib/net-http/0/net-http.rbs +162 -134
  283. data/stdlib/objspace/0/objspace.rbs +17 -34
  284. data/stdlib/open-uri/0/open-uri.rbs +48 -8
  285. data/stdlib/open3/0/open3.rbs +469 -10
  286. data/stdlib/openssl/0/openssl.rbs +521 -397
  287. data/stdlib/optparse/0/optparse.rbs +26 -17
  288. data/stdlib/pathname/0/pathname.rbs +11 -1381
  289. data/stdlib/pp/0/pp.rbs +9 -8
  290. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  291. data/stdlib/pstore/0/pstore.rbs +35 -30
  292. data/stdlib/psych/0/psych.rbs +65 -12
  293. data/stdlib/psych/0/store.rbs +2 -4
  294. data/stdlib/pty/0/pty.rbs +9 -6
  295. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  296. data/stdlib/rdoc/0/code_object.rbs +4 -3
  297. data/stdlib/rdoc/0/comment.rbs +2 -0
  298. data/stdlib/rdoc/0/options.rbs +76 -0
  299. data/stdlib/rdoc/0/parser.rbs +1 -1
  300. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  301. data/stdlib/rdoc/0/store.rbs +2 -2
  302. data/stdlib/resolv/0/resolv.rbs +26 -69
  303. data/stdlib/ripper/0/ripper.rbs +25 -19
  304. data/stdlib/securerandom/0/manifest.yaml +2 -0
  305. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  306. data/stdlib/shellwords/0/shellwords.rbs +3 -3
  307. data/stdlib/singleton/0/singleton.rbs +6 -0
  308. data/stdlib/socket/0/addrinfo.rbs +9 -9
  309. data/stdlib/socket/0/basic_socket.rbs +3 -3
  310. data/stdlib/socket/0/ip_socket.rbs +10 -8
  311. data/stdlib/socket/0/socket.rbs +23 -10
  312. data/stdlib/socket/0/tcp_server.rbs +1 -1
  313. data/stdlib/socket/0/tcp_socket.rbs +11 -3
  314. data/stdlib/socket/0/udp_socket.rbs +1 -1
  315. data/stdlib/socket/0/unix_server.rbs +1 -1
  316. data/stdlib/stringio/0/stringio.rbs +1211 -96
  317. data/stdlib/strscan/0/string_scanner.rbs +101 -80
  318. data/stdlib/tempfile/0/manifest.yaml +3 -0
  319. data/stdlib/tempfile/0/tempfile.rbs +25 -21
  320. data/stdlib/time/0/time.rbs +8 -6
  321. data/stdlib/timeout/0/timeout.rbs +58 -7
  322. data/stdlib/tsort/0/cyclic.rbs +4 -1
  323. data/stdlib/tsort/0/interfaces.rbs +8 -8
  324. data/stdlib/tsort/0/tsort.rbs +16 -15
  325. data/stdlib/uri/0/common.rbs +42 -20
  326. data/stdlib/uri/0/file.rbs +3 -3
  327. data/stdlib/uri/0/generic.rbs +21 -18
  328. data/stdlib/uri/0/http.rbs +2 -2
  329. data/stdlib/uri/0/ldap.rbs +2 -2
  330. data/stdlib/uri/0/mailto.rbs +3 -3
  331. data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
  332. data/stdlib/zlib/0/deflate.rbs +4 -3
  333. data/stdlib/zlib/0/gzip_file.rbs +1 -1
  334. data/stdlib/zlib/0/gzip_reader.rbs +8 -8
  335. data/stdlib/zlib/0/gzip_writer.rbs +16 -13
  336. data/stdlib/zlib/0/inflate.rbs +1 -1
  337. data/stdlib/zlib/0/need_dict.rbs +1 -1
  338. data/wasm/README.md +109 -0
  339. data/wasm/rbs_wasm.c +479 -0
  340. metadata +133 -19
  341. data/ext/rbs_extension/lexer.c +0 -2728
  342. data/ext/rbs_extension/lexer.h +0 -179
  343. data/ext/rbs_extension/lexer.re +0 -147
  344. data/ext/rbs_extension/lexstate.c +0 -175
  345. data/ext/rbs_extension/location.c +0 -325
  346. data/ext/rbs_extension/location.h +0 -85
  347. data/ext/rbs_extension/parser.c +0 -2982
  348. data/ext/rbs_extension/parser.h +0 -18
  349. data/ext/rbs_extension/parserstate.c +0 -411
  350. data/ext/rbs_extension/parserstate.h +0 -163
  351. data/ext/rbs_extension/unescape.c +0 -32
  352. data/include/rbs/ruby_objs.h +0 -72
  353. data/src/constants.c +0 -153
  354. data/src/ruby_objs.c +0 -799
data/core/io.rbs CHANGED
@@ -7,9 +7,9 @@
7
7
  # classes in the Ruby standard library are also subclasses of IO; these include
8
8
  # TCPSocket and UDPSocket.
9
9
  #
10
- # The global constant ARGF (also accessible as `$<`) provides an IO-like stream
11
- # that allows access to all file paths found in ARGV (or found in STDIN if ARGV
12
- # is empty). ARGF is not itself a subclass of IO.
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
13
  #
14
14
  # Class StringIO provides an IO-like stream that handles a String. StringIO is
15
15
  # not itself a subclass of IO.
@@ -46,10 +46,10 @@
46
46
  # from the position mentioned above); see [Line
47
47
  # Number](rdoc-ref:IO@Line+Number).
48
48
  #
49
- # ## Extension `io/console`
49
+ # ## Extension <code>io/console</code>
50
50
  #
51
- # Extension `io/console` provides numerous methods for interacting with the
52
- # console; requiring it adds numerous methods to class IO.
51
+ # Extension <code>io/console</code> provides numerous methods for interacting
52
+ # with the console; requiring it adds numerous methods to class IO.
53
53
  #
54
54
  # ## Example Files
55
55
  #
@@ -86,23 +86,23 @@
86
86
  # A number of IO methods accept optional keyword arguments that determine how a
87
87
  # new stream is to be opened:
88
88
  #
89
- # * `:mode`: Stream mode.
90
- # * `:flags`: Integer file open flags; If `mode` is also given, the two are
91
- # bitwise-ORed.
92
- # * `:external_encoding`: External encoding for the stream.
93
- # * `:internal_encoding`: Internal encoding for the stream. `'-'` is a synonym
94
- # for the default internal encoding. If the value is `nil` no conversion
95
- # occurs.
96
- # * `:encoding`: Specifies external and internal encodings as
97
- # `'extern:intern'`.
98
- # * `:textmode`: If a truthy value, specifies the mode as text-only, binary
99
- # otherwise.
100
- # * `:binmode`: If a truthy value, specifies the mode as binary, text-only
101
- # otherwise.
102
- # * `:autoclose`: If a truthy value, specifies that the `fd` will close when
103
- # the stream closes; otherwise it remains open.
104
- # * `:path:` If a string value is provided, it is used in #inspect and is
105
- # available as #path method.
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
106
  #
107
107
  # Also available are the options offered in String#encode, which may control
108
108
  # conversion between external and internal encoding.
@@ -129,8 +129,8 @@
129
129
  #
130
130
  # The relevant methods:
131
131
  #
132
- # * IO#tell (aliased as `#pos`): Returns the current position (in bytes) in
133
- # the stream.
132
+ # * IO#tell (aliased as <code>#pos</code>): Returns the current position (in
133
+ # bytes) in the stream.
134
134
  # * IO#pos=: Sets the position of the stream to a given integer `new_position`
135
135
  # (in bytes).
136
136
  # * IO#seek: Sets the position of the stream to a given integer `offset` (in
@@ -158,8 +158,8 @@
158
158
  #
159
159
  # You can query whether a stream is positioned at its end:
160
160
  #
161
- # * IO#eof? (also aliased as `#eof`): Returns whether the stream is at
162
- # end-of-stream.
161
+ # * IO#eof? (also aliased as <code>#eof</code>): Returns whether the stream is
162
+ # at end-of-stream.
163
163
  #
164
164
  # You can reposition to end-of-stream by using method IO#seek:
165
165
  #
@@ -225,8 +225,8 @@
225
225
  # separator*: the string that determines what is considered a line; it is
226
226
  # sometimes called the *input record separator*.
227
227
  #
228
- # The default line separator is taken from global variable `$/`, whose initial
229
- # value is `"\n"`.
228
+ # The default line separator is taken from global variable <code>$/</code>,
229
+ # whose initial value is <code>"\n"</code>.
230
230
  #
231
231
  # Generally, the line to be read next is all data from the current
232
232
  # [position](rdoc-ref:IO@Position) to the next line separator (but see [Special
@@ -250,7 +250,7 @@
250
250
  # f.gets # => "e\n"
251
251
  # f.close
252
252
  #
253
- # Or by setting global variable `$/`:
253
+ # Or by setting global variable <code>$/</code>:
254
254
  #
255
255
  # f = File.new('t.txt')
256
256
  # $/ = 'l'
@@ -270,8 +270,8 @@
270
270
  # f.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
271
271
  # f.close
272
272
  #
273
- # * `''` (the empty string): The next "paragraph" is to be read (paragraphs
274
- # being separated by two consecutive line separators):
273
+ # * <code>''</code> (the empty string): The next "paragraph" is to be read
274
+ # (paragraphs being separated by two consecutive line separators):
275
275
  #
276
276
  # f = File.new('t.txt')
277
277
  # f.gets('') # => "First line\nSecond line\n\n"
@@ -285,8 +285,8 @@
285
285
  # multi-byte character will not be split, and so a returned line may be slightly
286
286
  # longer than the limit).
287
287
  #
288
- # The default limit value is `-1`; any negative limit value means that there is
289
- # no limit.
288
+ # The default limit value is <code>-1</code>; any negative limit value means
289
+ # that there is no limit.
290
290
  #
291
291
  # If there is no limit, the line is determined only by `sep`.
292
292
  #
@@ -385,10 +385,10 @@
385
385
  # f.lineno # => 1001
386
386
  # f.close
387
387
  #
388
- # Associated with the line number is the global variable `$.`:
388
+ # Associated with the line number is the global variable <code>$.</code>:
389
389
  #
390
- # * When a stream is opened, `$.` is not set; its value is left over from
391
- # previous activity in the process:
390
+ # * When a stream is opened, <code>$.</code> is not set; its value is left
391
+ # over from previous activity in the process:
392
392
  #
393
393
  # $. = 41
394
394
  # f = File.new('t.txt')
@@ -396,7 +396,8 @@
396
396
  # # => 41
397
397
  # f.close
398
398
  #
399
- # * When a stream is read, `$.` is set to the line number for that stream:
399
+ # * When a stream is read, <code>$.</code> is set to the line number for that
400
+ # stream:
400
401
  #
401
402
  # f0 = File.new('t.txt')
402
403
  # f1 = File.new('t.dat')
@@ -407,7 +408,7 @@
407
408
  # f0.close
408
409
  # f1.close
409
410
  #
410
- # * Methods IO#rewind and IO#seek do not affect `$.`:
411
+ # * Methods IO#rewind and IO#seek do not affect <code>$.</code>:
411
412
  #
412
413
  # f = File.new('t.txt')
413
414
  # f.readlines # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
@@ -652,15 +653,17 @@ class IO < Object
652
653
  #
653
654
  # Argument `advice` is one of the following symbols:
654
655
  #
655
- # * `:normal`: The application has no advice to give about its access pattern
656
- # for the specified data. If no advice is given for an open file, this is
657
- # the default assumption.
658
- # * `:sequential`: The application expects to access the specified data
659
- # sequentially (with lower offsets read before higher ones).
660
- # * `:random`: The specified data will be accessed in random order.
661
- # * `:noreuse`: The specified data will be accessed only once.
662
- # * `:willneed`: The specified data will be accessed in the near future.
663
- # * `:dontneed`: The specified data will not be accessed in the near future.
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.
664
667
  #
665
668
  # Not implemented on all platforms.
666
669
  #
@@ -724,8 +727,8 @@ class IO < Object
724
727
  # If the stream is open for writing, flushes any buffered writes to the
725
728
  # operating system before closing.
726
729
  #
727
- # If the stream was opened by IO.popen, sets global variable `$?` (child exit
728
- # status).
730
+ # If the stream was opened by IO.popen, sets global variable <code>$?</code>
731
+ # (child exit status).
729
732
  #
730
733
  # It is not an error to close an IO object that has already been closed. It just
731
734
  # returns nil.
@@ -790,7 +793,7 @@ class IO < Object
790
793
  # and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
791
794
  #
792
795
  # If the stream was opened by IO.popen and is also closed for writing, sets
793
- # global variable `$?` (child exit status).
796
+ # global variable <code>$?</code> (child exit status).
794
797
  #
795
798
  # Example:
796
799
  #
@@ -824,7 +827,7 @@ class IO < Object
824
827
  # Flushes any buffered writes to the operating system before closing.
825
828
  #
826
829
  # If the stream was opened by IO.popen and is also closed for reading, sets
827
- # global variable `$?` (child exit status).
830
+ # global variable <code>$?</code> (child exit status).
828
831
  #
829
832
  # IO.popen('ruby', 'r+') do |pipe|
830
833
  # puts pipe.closed?
@@ -990,8 +993,8 @@ class IO < Object
990
993
  # - fdatasync -> 0
991
994
  # -->
992
995
  # Immediately writes to disk all data buffered in the stream, via the operating
993
- # system's: `fdatasync(2)`, if supported, otherwise via `fsync(2)`, if
994
- # supported; otherwise raises an exception.
996
+ # system's: <code>fdatasync(2)</code>, if supported, otherwise via
997
+ # <code>fsync(2)</code>, if supported; otherwise raises an exception.
995
998
  #
996
999
  def fdatasync: () -> Integer?
997
1000
 
@@ -1026,7 +1029,7 @@ class IO < Object
1026
1029
  # - fsync -> 0
1027
1030
  # -->
1028
1031
  # Immediately writes to disk all data buffered in the stream, via the operating
1029
- # system's `fsync(2)`.
1032
+ # system's <code>fsync(2)</code>.
1030
1033
  #
1031
1034
  # Note this difference:
1032
1035
  #
@@ -1036,7 +1039,8 @@ class IO < Object
1036
1039
  # * IO#fsync: Ensures both that data is flushed from internal buffers, and
1037
1040
  # that data is written to disk.
1038
1041
  #
1039
- # Raises an exception if the operating system does not support `fsync(2)`.
1042
+ # Raises an exception if the operating system does not support
1043
+ # <code>fsync(2)</code>.
1040
1044
  #
1041
1045
  def fsync: () -> Integer?
1042
1046
 
@@ -1082,11 +1086,11 @@ class IO < Object
1082
1086
  # - gets(limit, chomp: false) -> string or nil
1083
1087
  # - gets(sep, limit, chomp: false) -> string or nil
1084
1088
  # -->
1085
- # Reads and returns a line from the stream; assigns the return value to `$_`.
1086
- # See [Line IO](rdoc-ref:IO@Line+IO).
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).
1087
1091
  #
1088
1092
  # With no arguments given, returns the next line as determined by line separator
1089
- # `$/`, or `nil` if none:
1093
+ # <code>$/</code>, or `nil` if none:
1090
1094
  #
1091
1095
  # f = File.open('t.txt')
1092
1096
  # f.gets # => "First line\n"
@@ -1226,6 +1230,24 @@ class IO < Object
1226
1230
  #
1227
1231
  def ioctl: (Integer integer_cmd, String | Integer argument) -> Integer
1228
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
+
1229
1251
  # <!--
1230
1252
  # rdoc-file=io.c
1231
1253
  # - isatty -> true or false
@@ -1316,15 +1338,15 @@ class IO < Object
1316
1338
  # - print(*objects) -> nil
1317
1339
  # -->
1318
1340
  # Writes the given objects to the stream; returns `nil`. Appends the output
1319
- # record separator `$OUTPUT_RECORD_SEPARATOR` (`$\`), if it is not `nil`. See
1320
- # [Line IO](rdoc-ref:IO@Line+IO).
1341
+ # record separator <code>$OUTPUT_RECORD_SEPARATOR</code> (<code>$\</code>), if
1342
+ # it is not `nil`. See [Line IO](rdoc-ref:IO@Line+IO).
1321
1343
  #
1322
1344
  # With argument `objects` given, for each object:
1323
1345
  #
1324
1346
  # * Converts via its method `to_s` if not a string.
1325
1347
  # * Writes to the stream.
1326
1348
  # * If not the last object, writes the output field separator
1327
- # `$OUTPUT_FIELD_SEPARATOR` (`$,`) if it is not `nil`.
1349
+ # <code>$OUTPUT_FIELD_SEPARATOR</code> (<code>$,</code>) if it is not `nil`.
1328
1350
  #
1329
1351
  # With default separators:
1330
1352
  #
@@ -1356,8 +1378,8 @@ class IO < Object
1356
1378
  #
1357
1379
  # "0,0.0,0/1,0+0i,zero,zero\n"
1358
1380
  #
1359
- # With no argument given, writes the content of `$_` (which is usually the most
1360
- # recent user input):
1381
+ # With no argument given, writes the content of <code>$_</code> (which is
1382
+ # usually the most recent user input):
1361
1383
  #
1362
1384
  # f = File.open('t.tmp', 'w+')
1363
1385
  # gets # Sets $_ to the most recent user input.
@@ -1373,7 +1395,7 @@ class IO < Object
1373
1395
  # Formats and writes `objects` to the stream.
1374
1396
  #
1375
1397
  # For details on `format_string`, see [Format
1376
- # Specifications](rdoc-ref:format_specifications.rdoc).
1398
+ # Specifications](rdoc-ref:language/format_specifications.rdoc).
1377
1399
  #
1378
1400
  def printf: (String format_string, *untyped objects) -> nil
1379
1401
 
@@ -1395,7 +1417,8 @@ class IO < Object
1395
1417
  #
1396
1418
  # AA
1397
1419
  #
1398
- def putc: (Numeric | String object) -> (Numeric | String)
1420
+ def putc: (real) -> real
1421
+ | (String) -> String
1399
1422
 
1400
1423
  # <!--
1401
1424
  # rdoc-file=io.c
@@ -1406,13 +1429,13 @@ class IO < Object
1406
1429
  # newline sequence. If called without arguments, writes a newline. See [Line
1407
1430
  # IO](rdoc-ref:IO@Line+IO).
1408
1431
  #
1409
- # Note that each added newline is the character `"\n"<//tt>, not the output
1410
- # record separator (<tt>$\`).
1432
+ # Note that each added newline is the character <code>"\n"<//tt>, not the output
1433
+ # record separator (<tt>$\</code>).
1411
1434
  #
1412
1435
  # Treatment for each object:
1413
1436
  #
1414
1437
  # * String: writes the string.
1415
- # * Neither string nor array: writes `object.to_s`.
1438
+ # * Neither string nor array: writes <code>object.to_s</code>.
1416
1439
  # * Array: writes each element of the array; arrays may be nested.
1417
1440
  #
1418
1441
  # To keep these examples brief, we define this helper method:
@@ -1443,6 +1466,61 @@ class IO < Object
1443
1466
  #
1444
1467
  def puts: (*untyped objects) -> nil
1445
1468
 
1469
+ # <!--
1470
+ # rdoc-file=io.c
1471
+ # - pread(maxlen, offset) -> string
1472
+ # - pread(maxlen, offset, out_string) -> string
1473
+ # -->
1474
+ # Behaves like IO#readpartial, except that it:
1475
+ #
1476
+ # * Reads at the given `offset` (in bytes).
1477
+ # * Disregards, and does not modify, the stream's position (see
1478
+ # [Position](rdoc-ref:IO@Position)).
1479
+ # * Bypasses any user space buffering in the stream.
1480
+ #
1481
+ # Because this method does not disturb the stream's state (its position, in
1482
+ # particular), `pread` allows multiple threads and processes to use the same IO
1483
+ # object for reading at various offsets.
1484
+ #
1485
+ # f = File.open('t.txt')
1486
+ # f.read # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1487
+ # f.pos # => 52
1488
+ # # Read 12 bytes at offset 0.
1489
+ # f.pread(12, 0) # => "First line\n"
1490
+ # # Read 9 bytes at offset 8.
1491
+ # f.pread(9, 8) # => "ne\nSecon"
1492
+ # f.close
1493
+ #
1494
+ # Not available on some platforms.
1495
+ #
1496
+ def pread: (int maxlen, int offset, ?string? out_string) -> String
1497
+
1498
+ # <!--
1499
+ # rdoc-file=io.c
1500
+ # - pwrite(object, offset) -> integer
1501
+ # -->
1502
+ # Behaves like IO#write, except that it:
1503
+ #
1504
+ # * Writes at the given `offset` (in bytes).
1505
+ # * Disregards, and does not modify, the stream's position (see
1506
+ # [Position](rdoc-ref:IO@Position)).
1507
+ # * Bypasses any user space buffering in the stream.
1508
+ #
1509
+ # Because this method does not disturb the stream's state (its position, in
1510
+ # particular), `pwrite` allows multiple threads and processes to use the same IO
1511
+ # object for writing at various offsets.
1512
+ #
1513
+ # f = File.open('t.tmp', 'w+')
1514
+ # # Write 6 bytes at offset 3.
1515
+ # f.pwrite('ABCDEF', 3) # => 6
1516
+ # f.rewind
1517
+ # f.read # => "\u0000\u0000\u0000ABCDEF"
1518
+ # f.close
1519
+ #
1520
+ # Not available on some platforms.
1521
+ #
1522
+ def pwrite: (_ToS object, int offset) -> Integer
1523
+
1446
1524
  # <!--
1447
1525
  # rdoc-file=io.c
1448
1526
  # - read(maxlen = nil, out_string = nil) -> new_string, out_string, or nil
@@ -1464,7 +1542,7 @@ class IO < Object
1464
1542
  # * `out_string` given: encoding of `out_string` not modified.
1465
1543
  # * `out_string` not given: ASCII-8BIT is used.
1466
1544
  #
1467
- # **Without Argument `out_string`**
1545
+ # <strong>Without Argument `out_string`</strong>
1468
1546
  #
1469
1547
  # When argument `out_string` is omitted, the returned value is a new string:
1470
1548
  #
@@ -1479,7 +1557,7 @@ class IO < Object
1479
1557
  #
1480
1558
  # If `maxlen` is zero, returns an empty string.
1481
1559
  #
1482
- # ** With Argument `out_string`**
1560
+ # <strong> With Argument `out_string`</strong>
1483
1561
  #
1484
1562
  # When argument `out_string` is given, the returned value is `out_string`, whose
1485
1563
  # content is replaced:
@@ -1512,8 +1590,8 @@ class IO < Object
1512
1590
  #
1513
1591
  # Related: IO#write.
1514
1592
  #
1515
- def read: (?nil, ?string outbuf) -> String
1516
- | (int? length, ?string outbuf) -> String?
1593
+ def read: (?nil, ?string? outbuf) -> String
1594
+ | (int? length, ?string? outbuf) -> String?
1517
1595
 
1518
1596
  # <!--
1519
1597
  # rdoc-file=io.rb
@@ -1565,11 +1643,11 @@ class IO < Object
1565
1643
  #
1566
1644
  # By specifying a keyword argument *exception* to `false`, you can indicate that
1567
1645
  # read_nonblock should not raise an IO::WaitReadable exception, but return the
1568
- # symbol `:wait_readable` instead. At EOF, it will return nil instead of raising
1569
- # EOFError.
1646
+ # symbol <code>:wait_readable</code> instead. At EOF, it will return nil instead
1647
+ # of raising EOFError.
1570
1648
  #
1571
- def read_nonblock: (int len, ?string buf, ?exception: true) -> String
1572
- | (int len, ?string buf, exception: false) -> (String | :wait_readable | nil)
1649
+ def read_nonblock: (int len, ?string? buf, ?exception: true) -> String
1650
+ | (int len, ?string? buf, exception: false) -> (String | :wait_readable | nil)
1573
1651
 
1574
1652
  # <!--
1575
1653
  # rdoc-file=io.c
@@ -1626,11 +1704,11 @@ class IO < Object
1626
1704
  # - readlines(limit, chomp: false) -> array
1627
1705
  # - readlines(sep, limit, chomp: false) -> array
1628
1706
  # -->
1629
- # Reads and returns all remaining line from the stream; does not modify `$_`.
1630
- # See [Line IO](rdoc-ref:IO@Line+IO).
1707
+ # Reads and returns all remaining line from the stream; does not modify
1708
+ # <code>$_</code>. See [Line IO](rdoc-ref:IO@Line+IO).
1631
1709
  #
1632
- # With no arguments given, returns lines as determined by line separator `$/`,
1633
- # or `nil` if none:
1710
+ # With no arguments given, returns lines as determined by line separator
1711
+ # <code>$/</code>, or `nil` if none:
1634
1712
  #
1635
1713
  # f = File.new('t.txt')
1636
1714
  # f.readlines
@@ -1769,7 +1847,7 @@ class IO < Object
1769
1847
  # r.readpartial(4096) # => "def\n" "" "ghi\n"
1770
1848
  # r.readpartial(4096) # => "ghi\n" "" ""
1771
1849
  #
1772
- def readpartial: (int maxlen, ?string outbuf) -> String
1850
+ def readpartial: (int maxlen, ?string? outbuf) -> String
1773
1851
 
1774
1852
  # <!--
1775
1853
  # rdoc-file=io.c
@@ -1836,8 +1914,8 @@ class IO < Object
1836
1914
  # Seeks to the position given by integer `offset` (see
1837
1915
  # [Position](rdoc-ref:IO@Position)) and constant `whence`, which is one of:
1838
1916
  #
1839
- # * `:CUR` or `IO::SEEK_CUR`: Repositions the stream to its current position
1840
- # plus the given `offset`:
1917
+ # * <code>:CUR</code> or <code>IO::SEEK_CUR</code>: Repositions the stream to
1918
+ # its current position plus the given `offset`:
1841
1919
  #
1842
1920
  # f = File.open('t.txt')
1843
1921
  # f.tell # => 0
@@ -1847,8 +1925,8 @@ class IO < Object
1847
1925
  # f.tell # => 10
1848
1926
  # f.close
1849
1927
  #
1850
- # * `:END` or `IO::SEEK_END`: Repositions the stream to its end plus the given
1851
- # `offset`:
1928
+ # * <code>:END</code> or <code>IO::SEEK_END</code>: Repositions the stream to
1929
+ # its end plus the given `offset`:
1852
1930
  #
1853
1931
  # f = File.open('t.txt')
1854
1932
  # f.tell # => 0
@@ -1860,7 +1938,8 @@ class IO < Object
1860
1938
  # f.tell # => 12
1861
1939
  # f.close
1862
1940
  #
1863
- # * `:SET` or `IO:SEEK_SET`: Repositions the stream to the given `offset`:
1941
+ # * <code>:SET</code> or <code>IO:SEEK_SET</code>: Repositions the stream to
1942
+ # the given `offset`:
1864
1943
  #
1865
1944
  # f = File.open('t.txt')
1866
1945
  # f.tell # => 0
@@ -1888,7 +1967,7 @@ class IO < Object
1888
1967
  # Argument `int_enc`, if given, must be an Encoding object or a String with the
1889
1968
  # encoding name; it is assigned as the encoding for the internal string.
1890
1969
  #
1891
- # Argument `'ext_enc:int_enc'`, if given, is a string containing two
1970
+ # Argument <code>'ext_enc:int_enc'</code>, if given, is a string containing two
1892
1971
  # colon-separated encoding names; corresponding Encoding objects are assigned as
1893
1972
  # the external and internal encodings for the stream.
1894
1973
  #
@@ -1989,7 +2068,7 @@ class IO < Object
1989
2068
  #
1990
2069
  # This method should not be used with other stream-reader methods.
1991
2070
  #
1992
- def sysread: (Integer maxlen, String outbuf) -> String
2071
+ def sysread: (Integer maxlen, ?String? outbuf) -> String
1993
2072
 
1994
2073
  # <!--
1995
2074
  # rdoc-file=io.c
@@ -2258,11 +2337,11 @@ class IO < Object
2258
2337
  #
2259
2338
  # On some platforms such as Windows, write_nonblock is not supported according
2260
2339
  # to the kind of the IO object. In such cases, write_nonblock raises
2261
- # `Errno::EBADF`.
2340
+ # <code>Errno::EBADF</code>.
2262
2341
  #
2263
2342
  # By specifying a keyword argument *exception* to `false`, you can indicate that
2264
2343
  # write_nonblock should not raise an IO::WaitWritable exception, but return the
2265
- # symbol `:wait_writable` instead.
2344
+ # symbol <code>:wait_writable</code> instead.
2266
2345
  #
2267
2346
  def write_nonblock: (_ToS s, ?exception: true) -> Integer
2268
2347
  | (_ToS s, exception: false) -> (Integer | :wait_writable | nil)
@@ -2274,11 +2353,7 @@ class IO < Object
2274
2353
  # Behaves like IO.read, except that the stream is opened in binary mode with
2275
2354
  # ASCII-8BIT encoding.
2276
2355
  #
2277
- # When called from class IO (but not subclasses of IO), this method has
2278
- # potential security vulnerabilities if called with untrusted input; see
2279
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2280
- #
2281
- def self.binread: (String name, ?Integer? length, ?Integer offset) -> String
2356
+ def self.binread: (path name, ?Integer? length, ?Integer offset) -> String
2282
2357
 
2283
2358
  # <!--
2284
2359
  # rdoc-file=io.c
@@ -2287,11 +2362,7 @@ class IO < Object
2287
2362
  # Behaves like IO.write, except that the stream is opened in binary mode with
2288
2363
  # ASCII-8BIT encoding.
2289
2364
  #
2290
- # When called from class IO (but not subclasses of IO), this method has
2291
- # potential security vulnerabilities if called with untrusted input; see
2292
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2293
- #
2294
- def self.binwrite: (String name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
2365
+ def self.binwrite: (path name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
2295
2366
 
2296
2367
  # <!--
2297
2368
  # rdoc-file=io.c
@@ -2304,15 +2375,15 @@ class IO < Object
2304
2375
  #
2305
2376
  # * The path to a readable file, from which source data is to be read.
2306
2377
  # * An IO-like object, opened for reading and capable of responding to
2307
- # method `:readpartial` or method `:read`.
2378
+ # method <code>:readpartial</code> or method <code>:read</code>.
2308
2379
  #
2309
2380
  # * The given `dst` must be one of the following:
2310
2381
  #
2311
2382
  # * The path to a writable file, to which data is to be written.
2312
2383
  # * An IO-like object, opened for writing and capable of responding to
2313
- # method `:write`.
2384
+ # method <code>:write</code>.
2314
2385
  #
2315
- # The examples here use file `t.txt` as source:
2386
+ # The examples here use file <code>t.txt</code> as source:
2316
2387
  #
2317
2388
  # File.read('t.txt')
2318
2389
  # # => "First line\nSecond line\n\nThird line\nFourth line\n"
@@ -2354,15 +2425,16 @@ class IO < Object
2354
2425
  # connected to a new stream `io`.
2355
2426
  #
2356
2427
  # This method has potential security vulnerabilities if called with untrusted
2357
- # input; see [Command Injection](rdoc-ref:command_injection.rdoc).
2428
+ # input; see [Command Injection](rdoc-ref:security/command_injection.rdoc).
2358
2429
  #
2359
2430
  # If no block is given, returns the new stream, which depending on given `mode`
2360
2431
  # may be open for reading, writing, or both. The stream should be explicitly
2361
2432
  # closed (eventually) to avoid resource leaks.
2362
2433
  #
2363
2434
  # If a block is given, the stream is passed to the block (again, open for
2364
- # reading, writing, or both); when the block exits, the stream is closed, and
2365
- # the block's value is assigned to global variable `$?` and returned.
2435
+ # reading, writing, or both); when the block exits, the stream is closed, the
2436
+ # block's value is returned, and the global variable <code>$?</code> is set to
2437
+ # the child's exit status.
2366
2438
  #
2367
2439
  # Optional argument `mode` may be any valid IO mode. See [Access
2368
2440
  # Modes](rdoc-ref:File@Access+Modes).
@@ -2391,10 +2463,10 @@ class IO < Object
2391
2463
  # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2392
2464
  # * Options for Kernel#spawn.
2393
2465
  #
2394
- # **Forked \Process**
2466
+ # **Forked Process**
2395
2467
  #
2396
- # When argument `cmd` is the 1-character string `'-'`, causes the process to
2397
- # fork:
2468
+ # When argument `cmd` is the 1-character string <code>'-'</code>, causes the
2469
+ # process to fork:
2398
2470
  # IO.popen('-') do |pipe|
2399
2471
  # if pipe
2400
2472
  # $stderr.puts "In parent, child pid is #{pipe.pid}\n"
@@ -2412,8 +2484,8 @@ class IO < Object
2412
2484
  #
2413
2485
  # **Shell Subprocess**
2414
2486
  #
2415
- # When argument `cmd` is a single string (but not `'-'`), the program named
2416
- # `cmd` is run as a shell command:
2487
+ # When argument `cmd` is a single string (but not <code>'-'</code>), the program
2488
+ # named `cmd` is run as a shell command:
2417
2489
  #
2418
2490
  # IO.popen('uname') do |pipe|
2419
2491
  # pipe.readlines
@@ -2437,8 +2509,8 @@ class IO < Object
2437
2509
  #
2438
2510
  # **Program Subprocess**
2439
2511
  #
2440
- # When argument `cmd` is an array of strings, the program named `cmd[0]` is run
2441
- # with all elements of `cmd` as its arguments:
2512
+ # When argument `cmd` is an array of strings, the program named
2513
+ # <code>cmd[0]</code> is run with all elements of `cmd` as its arguments:
2442
2514
  #
2443
2515
  # IO.popen(['du', '..', '.']) do |pipe|
2444
2516
  # $stderr.puts pipe.readlines.size
@@ -2448,18 +2520,19 @@ class IO < Object
2448
2520
  #
2449
2521
  # 1111
2450
2522
  #
2451
- # **Program Subprocess with `argv0`**
2523
+ # <strong>Program Subprocess with `argv0`</strong>
2452
2524
  #
2453
2525
  # When argument `cmd` is an array whose first element is a 2-element string
2454
2526
  # array and whose remaining elements (if any) are strings:
2455
2527
  #
2456
- # * `cmd[0][0]` (the first string in the nested array) is the name of a
2457
- # program that is run.
2458
- # * `cmd[0][1]` (the second string in the nested array) is set as the
2459
- # program's `argv[0]`.
2460
- # * `cmd[1..-1]` (the strings in the outer array) are the program's arguments.
2528
+ # * <code>cmd[0][0]</code> (the first string in the nested array) is the name
2529
+ # of a program that is run.
2530
+ # * <code>cmd[0][1]</code> (the second string in the nested array) is set as
2531
+ # the program's <code>argv[0]</code>.
2532
+ # * <code>cmd[1..-1]</code> (the strings in the outer array) are the program's
2533
+ # arguments.
2461
2534
  #
2462
- # Example (sets `$0` to 'foo'):
2535
+ # Example (sets <code>$0</code> to 'foo'):
2463
2536
  #
2464
2537
  # IO.popen([['/bin/sh', 'foo'], '-c', 'echo $0']).read # => "foo\n"
2465
2538
  #
@@ -2503,10 +2576,10 @@ class IO < Object
2503
2576
  #
2504
2577
  # Raises exceptions that IO.pipe and Kernel.spawn raise.
2505
2578
  #
2506
- 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: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) -> instance
2507
- | (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: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) -> instance
2508
- | [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: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) { (instance) -> X } -> X
2509
- | [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: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: boolish, ?chdir: String) { (instance) -> X } -> X
2579
+ 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
2580
+ | (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
2581
+ | [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
2582
+ | [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
2510
2583
 
2511
2584
  # The command can be given as:
2512
2585
  #
@@ -2526,10 +2599,6 @@ class IO < Object
2526
2599
  # -->
2527
2600
  # Calls the block with each successive line read from the stream.
2528
2601
  #
2529
- # When called from class IO (but not subclasses of IO), this method has
2530
- # potential security vulnerabilities if called with untrusted input; see
2531
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2532
- #
2533
2602
  # The first argument must be a string that is the path to a file.
2534
2603
  #
2535
2604
  # With only argument `path` given, parses lines from the file at the given
@@ -2594,8 +2663,8 @@ class IO < Object
2594
2663
  #
2595
2664
  # Returns an Enumerator if no block is given.
2596
2665
  #
2597
- def self.foreach: (string | _ToPath 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
2598
- | (string | _ToPath 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]
2666
+ 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
2667
+ | (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]
2599
2668
 
2600
2669
  # <!--
2601
2670
  # rdoc-file=io.c
@@ -2651,8 +2720,8 @@ class IO < Object
2651
2720
  # In the example below, the two processes close the ends of the pipe that they
2652
2721
  # are not using. This is not just a cosmetic nicety. The read end of a pipe will
2653
2722
  # not generate an end of file condition if there are any writers with the pipe
2654
- # still open. In the case of the parent process, the `rd.read` will never return
2655
- # if it does not first issue a `wr.close`:
2723
+ # still open. In the case of the parent process, the <code>rd.read</code> will
2724
+ # never return if it does not first issue a <code>wr.close</code>:
2656
2725
  #
2657
2726
  # rd, wr = IO.pipe
2658
2727
  #
@@ -2668,7 +2737,7 @@ class IO < Object
2668
2737
  # wr.close
2669
2738
  # end
2670
2739
  #
2671
- # *produces:*
2740
+ # <em>produces:</em>
2672
2741
  #
2673
2742
  # Sending message to parent
2674
2743
  # Parent got: <Hi Dad>
@@ -2683,10 +2752,6 @@ class IO < Object
2683
2752
  # Opens the stream, reads and returns some or all of its content, and closes the
2684
2753
  # stream; returns `nil` if no bytes were read.
2685
2754
  #
2686
- # When called from class IO (but not subclasses of IO), this method has
2687
- # potential security vulnerabilities if called with untrusted input; see
2688
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2689
- #
2690
2755
  # The first argument must be a string that is the path to a file.
2691
2756
  #
2692
2757
  # With only argument `path` given, reads in text mode and returns the entire
@@ -2716,7 +2781,7 @@ class IO < Object
2716
2781
  # * [Open Options](rdoc-ref:IO@Open+Options).
2717
2782
  # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2718
2783
  #
2719
- def self.read: (String 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
+ 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
2720
2785
 
2721
2786
  # <!--
2722
2787
  # rdoc-file=io.c
@@ -2726,10 +2791,6 @@ class IO < Object
2726
2791
  # -->
2727
2792
  # Returns an array of all lines read from the stream.
2728
2793
  #
2729
- # When called from class IO (but not subclasses of IO), this method has
2730
- # potential security vulnerabilities if called with untrusted input; see
2731
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2732
- #
2733
2794
  # The first argument must be a string that is the path to a file.
2734
2795
  #
2735
2796
  # With only argument `path` given, parses lines from the file at the given
@@ -2769,7 +2830,7 @@ class IO < Object
2769
2830
  # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2770
2831
  # * [Line Options](rdoc-ref:IO@Line+IO).
2771
2832
  #
2772
- def self.readlines: (String | _ToPath 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
+ 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]
2773
2834
 
2774
2835
  # <!--
2775
2836
  # rdoc-file=io.c
@@ -2785,7 +2846,9 @@ class IO < Object
2785
2846
  # IO objects.
2786
2847
  #
2787
2848
  # Argument `timeout` is a numeric value (such as integer or float) timeout
2788
- # interval in seconds.
2849
+ # interval in seconds. `timeout` can also be `nil` or
2850
+ # <code>Float::INFINITY</code>. `nil` and <code>Float::INFINITY</code> means no
2851
+ # timeout.
2789
2852
  #
2790
2853
  # The method monitors the IO objects given in all three arrays, waiting for some
2791
2854
  # to be ready; returns a 3-element array whose elements are:
@@ -2860,8 +2923,8 @@ class IO < Object
2860
2923
  #
2861
2924
  # The writability notified by select(2) doesn't show how many bytes are
2862
2925
  # writable. IO#write method blocks until given whole string is written. So,
2863
- # `IO#write(two or more bytes)` can block after writability is notified by
2864
- # IO.select. IO#write_nonblock is required to avoid the blocking.
2926
+ # <code>IO#write(two or more bytes)</code> can block after writability is
2927
+ # notified by IO.select. IO#write_nonblock is required to avoid the blocking.
2865
2928
  #
2866
2929
  # Blocking write (#write) can be emulated using #write_nonblock and IO.select as
2867
2930
  # follows: IO::WaitReadable should also be rescued for SSL renegotiation in
@@ -2950,10 +3013,6 @@ class IO < Object
2950
3013
  # Opens the stream, writes the given `data` to it, and closes the stream;
2951
3014
  # returns the number of bytes written.
2952
3015
  #
2953
- # When called from class IO (but not subclasses of IO), this method has
2954
- # potential security vulnerabilities if called with untrusted input; see
2955
- # [Command Injection](rdoc-ref:command_injection.rdoc).
2956
- #
2957
3016
  # The first argument must be a string that is the path to a file.
2958
3017
  #
2959
3018
  # With only argument `path` given, writes the given `data` to the file at that
@@ -2976,7 +3035,7 @@ class IO < Object
2976
3035
  # File.read('t.tmp') # => "ab012f"
2977
3036
  #
2978
3037
  # If `offset` is outside the file content, the file is padded with null
2979
- # characters `"\u0000"`:
3038
+ # characters <code>"\u0000"</code>:
2980
3039
  #
2981
3040
  # IO.write('t.tmp', 'xyz', 10) # => 3
2982
3041
  # File.read('t.tmp') # => "ab012f\u0000\u0000\u0000\u0000xyz"
@@ -2986,7 +3045,7 @@ class IO < Object
2986
3045
  # * [Open Options](rdoc-ref:IO@Open+Options).
2987
3046
  # * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
2988
3047
  #
2989
- def self.write: (String 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
+ 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
2990
3049
 
2991
3050
  # <!--
2992
3051
  # rdoc-file=io.c
@@ -3015,7 +3074,8 @@ class IO < Object
3015
3074
  # Calls the block with each remaining line read from the stream; returns `self`.
3016
3075
  # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
3017
3076
  #
3018
- # With no arguments given, reads lines as determined by line separator `$/`:
3077
+ # With no arguments given, reads lines as determined by line separator
3078
+ # <code>$/</code>:
3019
3079
  #
3020
3080
  # f = File.new('t.txt')
3021
3081
  # f.each_line {|line| p line }
@@ -3117,7 +3177,8 @@ class IO < Object
3117
3177
  # Calls the block with each remaining line read from the stream; returns `self`.
3118
3178
  # Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
3119
3179
  #
3120
- # With no arguments given, reads lines as determined by line separator `$/`:
3180
+ # With no arguments given, reads lines as determined by line separator
3181
+ # <code>$/</code>:
3121
3182
  #
3122
3183
  # f = File.new('t.txt')
3123
3184
  # f.each_line {|line| p line }
@@ -3404,3 +3465,9 @@ end
3404
3465
  #
3405
3466
  module IO::WaitWritable
3406
3467
  end
3468
+
3469
+ # <!-- rdoc-file=io.c -->
3470
+ # Can be raised by IO operations when IO#timeout= is set.
3471
+ #
3472
+ class IO::TimeoutError < IOError
3473
+ end