rbs 3.10.4 → 4.0.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 (267) hide show
  1. checksums.yaml +4 -4
  2. data/.github/dependabot.yml +14 -14
  3. data/.github/workflows/bundle-update.yml +60 -0
  4. data/.github/workflows/c-check.yml +7 -5
  5. data/.github/workflows/comments.yml +2 -2
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/ruby.yml +16 -26
  8. data/.github/workflows/rust.yml +95 -0
  9. data/.github/workflows/typecheck.yml +1 -1
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +2 -2
  12. data/.vscode/extensions.json +5 -0
  13. data/.vscode/settings.json +19 -0
  14. data/CHANGELOG.md +202 -2
  15. data/Rakefile +9 -23
  16. data/Steepfile +2 -0
  17. data/config.yml +457 -13
  18. data/core/array.rbs +218 -188
  19. data/core/basic_object.rbs +9 -8
  20. data/core/binding.rbs +0 -2
  21. data/core/builtin.rbs +2 -2
  22. data/core/class.rbs +6 -5
  23. data/core/comparable.rbs +45 -31
  24. data/core/complex.rbs +66 -55
  25. data/core/dir.rbs +57 -45
  26. data/core/encoding.rbs +6 -6
  27. data/core/enumerable.rbs +105 -91
  28. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  29. data/core/enumerator.rbs +24 -3
  30. data/core/errno.rbs +3 -2
  31. data/core/errors.rbs +31 -29
  32. data/core/exception.rbs +12 -12
  33. data/core/fiber.rbs +47 -36
  34. data/core/file.rbs +242 -169
  35. data/core/file_test.rbs +2 -2
  36. data/core/float.rbs +42 -68
  37. data/core/gc.rbs +78 -70
  38. data/core/hash.rbs +70 -60
  39. data/core/integer.rbs +32 -75
  40. data/core/io/buffer.rbs +36 -36
  41. data/core/io/wait.rbs +7 -7
  42. data/core/io.rbs +192 -146
  43. data/core/kernel.rbs +198 -147
  44. data/core/marshal.rbs +3 -3
  45. data/core/match_data.rbs +14 -12
  46. data/core/math.rbs +69 -67
  47. data/core/method.rbs +6 -8
  48. data/core/module.rbs +148 -88
  49. data/core/nil_class.rbs +4 -3
  50. data/core/numeric.rbs +53 -50
  51. data/core/object.rbs +6 -8
  52. data/core/object_space.rbs +11 -10
  53. data/core/pathname.rbs +131 -81
  54. data/core/proc.rbs +65 -34
  55. data/core/process.rbs +221 -201
  56. data/core/ractor.rbs +15 -11
  57. data/core/random.rbs +21 -3
  58. data/core/range.rbs +152 -49
  59. data/core/rational.rbs +5 -56
  60. data/core/rbs/unnamed/argf.rbs +58 -51
  61. data/core/rbs/unnamed/env_class.rbs +18 -13
  62. data/core/rbs/unnamed/main_class.rbs +123 -0
  63. data/core/rbs/unnamed/random.rbs +7 -116
  64. data/core/regexp.rbs +236 -197
  65. data/core/ruby.rbs +1 -1
  66. data/core/ruby_vm.rbs +32 -30
  67. data/core/rubygems/config_file.rbs +5 -5
  68. data/core/rubygems/errors.rbs +1 -1
  69. data/core/rubygems/requirement.rbs +5 -5
  70. data/core/rubygems/rubygems.rbs +5 -3
  71. data/core/set.rbs +17 -16
  72. data/core/signal.rbs +2 -2
  73. data/core/string.rbs +318 -298
  74. data/core/struct.rbs +26 -25
  75. data/core/symbol.rbs +25 -24
  76. data/core/thread.rbs +40 -41
  77. data/core/time.rbs +47 -42
  78. data/core/trace_point.rbs +34 -31
  79. data/core/true_class.rbs +2 -2
  80. data/core/unbound_method.rbs +10 -10
  81. data/core/warning.rbs +7 -7
  82. data/docs/collection.md +1 -1
  83. data/docs/config.md +171 -0
  84. data/docs/inline.md +576 -0
  85. data/docs/syntax.md +46 -16
  86. data/docs/type_fingerprint.md +21 -0
  87. data/exe/rbs +1 -1
  88. data/ext/rbs_extension/ast_translation.c +595 -98
  89. data/ext/rbs_extension/class_constants.c +30 -0
  90. data/ext/rbs_extension/class_constants.h +15 -0
  91. data/ext/rbs_extension/legacy_location.c +30 -53
  92. data/ext/rbs_extension/legacy_location.h +37 -0
  93. data/ext/rbs_extension/main.c +125 -24
  94. data/include/rbs/ast.h +485 -150
  95. data/include/rbs/lexer.h +11 -4
  96. data/include/rbs/location.h +25 -44
  97. data/include/rbs/parser.h +20 -2
  98. data/include/rbs/util/rbs_constant_pool.h +0 -3
  99. data/include/rbs.h +8 -0
  100. data/lib/rbs/ast/annotation.rb +1 -1
  101. data/lib/rbs/ast/comment.rb +1 -1
  102. data/lib/rbs/ast/declarations.rb +10 -10
  103. data/lib/rbs/ast/members.rb +14 -14
  104. data/lib/rbs/ast/ruby/annotations.rb +409 -0
  105. data/lib/rbs/ast/ruby/comment_block.rb +245 -0
  106. data/lib/rbs/ast/ruby/declarations.rb +281 -0
  107. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
  108. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  109. data/lib/rbs/ast/ruby/members.rb +723 -0
  110. data/lib/rbs/ast/type_param.rb +24 -4
  111. data/lib/rbs/buffer.rb +105 -20
  112. data/lib/rbs/cli/diff.rb +16 -15
  113. data/lib/rbs/cli/validate.rb +62 -125
  114. data/lib/rbs/cli.rb +55 -23
  115. data/lib/rbs/collection/config/lockfile_generator.rb +8 -4
  116. data/lib/rbs/collection/sources/git.rb +1 -0
  117. data/lib/rbs/collection.rb +0 -1
  118. data/lib/rbs/definition.rb +6 -1
  119. data/lib/rbs/definition_builder/ancestor_builder.rb +119 -63
  120. data/lib/rbs/definition_builder/method_builder.rb +65 -30
  121. data/lib/rbs/definition_builder.rb +177 -20
  122. data/lib/rbs/diff.rb +7 -1
  123. data/lib/rbs/environment/class_entry.rb +69 -0
  124. data/lib/rbs/environment/module_entry.rb +66 -0
  125. data/lib/rbs/environment.rb +338 -155
  126. data/lib/rbs/environment_loader.rb +2 -2
  127. data/lib/rbs/errors.rb +30 -20
  128. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  129. data/lib/rbs/inline_parser.rb +542 -0
  130. data/lib/rbs/location_aux.rb +36 -4
  131. data/lib/rbs/locator.rb +5 -1
  132. data/lib/rbs/method_type.rb +5 -3
  133. data/lib/rbs/namespace.rb +0 -7
  134. data/lib/rbs/parser_aux.rb +31 -8
  135. data/lib/rbs/prototype/helpers.rb +57 -0
  136. data/lib/rbs/prototype/rb.rb +3 -28
  137. data/lib/rbs/prototype/rbi.rb +3 -20
  138. data/lib/rbs/prototype/runtime.rb +10 -2
  139. data/lib/rbs/resolver/type_name_resolver.rb +0 -8
  140. data/lib/rbs/source.rb +99 -0
  141. data/lib/rbs/subtractor.rb +4 -3
  142. data/lib/rbs/test/type_check.rb +5 -2
  143. data/lib/rbs/type_name.rb +1 -8
  144. data/lib/rbs/types.rb +88 -78
  145. data/lib/rbs/unit_test/convertibles.rb +1 -0
  146. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  147. data/lib/rbs/validator.rb +2 -2
  148. data/lib/rbs/version.rb +1 -1
  149. data/lib/rbs.rb +12 -1
  150. data/rbs.gemspec +3 -2
  151. data/rust/.gitignore +1 -0
  152. data/rust/Cargo.lock +378 -0
  153. data/rust/Cargo.toml +7 -0
  154. data/rust/ruby-rbs/Cargo.toml +22 -0
  155. data/rust/ruby-rbs/build.rs +764 -0
  156. data/rust/ruby-rbs/examples/locations.rs +60 -0
  157. data/rust/ruby-rbs/src/lib.rs +1 -0
  158. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  159. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  160. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  161. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  162. data/rust/ruby-rbs-sys/build.rs +204 -0
  163. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  164. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  165. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  166. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  167. data/schema/typeParam.json +17 -1
  168. data/sig/ancestor_builder.rbs +1 -1
  169. data/sig/ast/ruby/annotations.rbs +421 -0
  170. data/sig/ast/ruby/comment_block.rbs +127 -0
  171. data/sig/ast/ruby/declarations.rbs +158 -0
  172. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  173. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  174. data/sig/ast/ruby/members.rbs +178 -0
  175. data/sig/buffer.rbs +63 -5
  176. data/sig/cli/diff.rbs +5 -11
  177. data/sig/cli/validate.rbs +12 -8
  178. data/sig/cli.rbs +18 -18
  179. data/sig/definition.rbs +6 -0
  180. data/sig/definition_builder.rbs +3 -1
  181. data/sig/environment/class_entry.rbs +50 -0
  182. data/sig/environment/module_entry.rbs +50 -0
  183. data/sig/environment.rbs +37 -81
  184. data/sig/errors.rbs +26 -20
  185. data/sig/inline_parser/comment_association.rbs +71 -0
  186. data/sig/inline_parser.rbs +124 -0
  187. data/sig/location.rbs +32 -7
  188. data/sig/locator.rbs +0 -2
  189. data/sig/method_builder.rbs +9 -4
  190. data/sig/namespace.rbs +0 -5
  191. data/sig/parser.rbs +47 -13
  192. data/sig/prototype/helpers.rbs +2 -0
  193. data/sig/resolver/type_name_resolver.rbs +0 -3
  194. data/sig/source.rbs +48 -0
  195. data/sig/type_param.rbs +13 -8
  196. data/sig/typename.rbs +0 -5
  197. data/sig/types.rbs +6 -7
  198. data/sig/unit_test/spy.rbs +0 -8
  199. data/sig/unit_test/type_assertions.rbs +11 -0
  200. data/src/ast.c +491 -143
  201. data/src/lexer.c +1552 -1314
  202. data/src/lexer.re +7 -0
  203. data/src/lexstate.c +8 -1
  204. data/src/location.c +8 -48
  205. data/src/parser.c +1107 -409
  206. data/src/util/rbs_constant_pool.c +0 -4
  207. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
  208. data/stdlib/cgi-escape/0/escape.rbs +4 -4
  209. data/stdlib/coverage/0/coverage.rbs +4 -3
  210. data/stdlib/date/0/date.rbs +33 -28
  211. data/stdlib/date/0/date_time.rbs +24 -23
  212. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  213. data/stdlib/digest/0/digest.rbs +110 -0
  214. data/stdlib/erb/0/erb.rbs +64 -53
  215. data/stdlib/etc/0/etc.rbs +55 -50
  216. data/stdlib/fileutils/0/fileutils.rbs +140 -126
  217. data/stdlib/forwardable/0/forwardable.rbs +10 -10
  218. data/stdlib/io-console/0/io-console.rbs +2 -2
  219. data/stdlib/json/0/json.rbs +158 -131
  220. data/stdlib/monitor/0/monitor.rbs +3 -3
  221. data/stdlib/net-http/0/net-http.rbs +159 -134
  222. data/stdlib/objspace/0/objspace.rbs +8 -30
  223. data/stdlib/open-uri/0/open-uri.rbs +8 -8
  224. data/stdlib/open3/0/open3.rbs +469 -10
  225. data/stdlib/openssl/0/openssl.rbs +144 -129
  226. data/stdlib/optparse/0/optparse.rbs +23 -14
  227. data/stdlib/pathname/0/pathname.rbs +2 -2
  228. data/stdlib/pp/0/pp.rbs +9 -8
  229. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  230. data/stdlib/pstore/0/pstore.rbs +35 -30
  231. data/stdlib/psych/0/psych.rbs +62 -9
  232. data/stdlib/psych/0/store.rbs +2 -4
  233. data/stdlib/pty/0/pty.rbs +9 -6
  234. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  235. data/stdlib/rdoc/0/code_object.rbs +2 -1
  236. data/stdlib/rdoc/0/parser.rbs +1 -1
  237. data/stdlib/rdoc/0/store.rbs +1 -1
  238. data/stdlib/ripper/0/ripper.rbs +20 -17
  239. data/stdlib/securerandom/0/manifest.yaml +2 -0
  240. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  241. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  242. data/stdlib/socket/0/addrinfo.rbs +9 -9
  243. data/stdlib/socket/0/basic_socket.rbs +3 -3
  244. data/stdlib/socket/0/ip_socket.rbs +10 -8
  245. data/stdlib/socket/0/socket.rbs +10 -9
  246. data/stdlib/socket/0/tcp_server.rbs +1 -1
  247. data/stdlib/socket/0/tcp_socket.rbs +1 -1
  248. data/stdlib/socket/0/udp_socket.rbs +1 -1
  249. data/stdlib/socket/0/unix_server.rbs +1 -1
  250. data/stdlib/stringio/0/stringio.rbs +55 -54
  251. data/stdlib/strscan/0/string_scanner.rbs +46 -44
  252. data/stdlib/tempfile/0/tempfile.rbs +24 -20
  253. data/stdlib/time/0/time.rbs +7 -5
  254. data/stdlib/tsort/0/tsort.rbs +7 -6
  255. data/stdlib/uri/0/common.rbs +31 -18
  256. data/stdlib/uri/0/file.rbs +2 -2
  257. data/stdlib/uri/0/generic.rbs +9 -2
  258. data/stdlib/uri/0/http.rbs +2 -2
  259. data/stdlib/uri/0/ldap.rbs +2 -2
  260. data/stdlib/uri/0/mailto.rbs +3 -3
  261. data/stdlib/uri/0/rfc2396_parser.rbs +6 -5
  262. data/stdlib/zlib/0/deflate.rbs +4 -3
  263. data/stdlib/zlib/0/gzip_reader.rbs +6 -6
  264. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  265. data/stdlib/zlib/0/inflate.rbs +1 -1
  266. data/stdlib/zlib/0/need_dict.rbs +1 -1
  267. metadata +66 -3
@@ -2,7 +2,7 @@
2
2
  # The objspace library extends the ObjectSpace module and adds several methods
3
3
  # to get internal statistic information about object/memory management.
4
4
  #
5
- # You need to `require 'objspace'` to use this extension module.
5
+ # You need to <code>require 'objspace'</code> to use this extension module.
6
6
  #
7
7
  # Generally, you **SHOULD** **NOT** use this library if you do not know about
8
8
  # the MRI implementation. Mainly, this library is for (memory) profiler
@@ -126,29 +126,6 @@ module ObjectSpace
126
126
  #
127
127
  def self?.count_imemo_objects: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
128
128
 
129
- # <!--
130
- # rdoc-file=ext/objspace/objspace.c
131
- # - ObjectSpace.count_nodes([result_hash]) -> hash
132
- # -->
133
- # Counts nodes for each node type.
134
- #
135
- # This method is only for MRI developers interested in performance and memory
136
- # usage of Ruby programs.
137
- #
138
- # It returns a hash as:
139
- #
140
- # {:NODE_METHOD=>2027, :NODE_FBODY=>1927, :NODE_CFUNC=>1798, ...}
141
- #
142
- # If the optional argument, result_hash, is given, it is overwritten and
143
- # returned. This is intended to avoid probe effect.
144
- #
145
- # Note: The contents of the returned hash is implementation defined. It may be
146
- # changed in future.
147
- #
148
- # This method is only expected to work with C Ruby.
149
- #
150
- def self?.count_nodes: (?Hash[Symbol, Integer] result_hash) -> Hash[Symbol, Integer]
151
-
152
129
  # <!--
153
130
  # rdoc-file=ext/objspace/objspace.c
154
131
  # - ObjectSpace.count_objects_size([result_hash]) -> hash
@@ -237,12 +214,13 @@ module ObjectSpace
237
214
  # -->
238
215
  # Dump the contents of a ruby object as JSON.
239
216
  #
240
- # *output* can be one of: `:stdout`, `:file`, `:string`, or IO object.
217
+ # *output* can be one of: <code>:stdout</code>, <code>:file</code>,
218
+ # <code>:string</code>, or IO object.
241
219
  #
242
- # * `:file` means dumping to a tempfile and returning corresponding File
243
- # object;
244
- # * `:stdout` means printing the dump and returning `nil`;
245
- # * `:string` means returning a string with the dump;
220
+ # * <code>:file</code> means dumping to a tempfile and returning corresponding
221
+ # File object;
222
+ # * <code>:stdout</code> means printing the dump and returning `nil`;
223
+ # * <code>:string</code> means returning a string with the dump;
246
224
  # * if an instance of IO object is provided, the output goes there, and the
247
225
  # object is returned.
248
226
  #
@@ -277,7 +255,7 @@ module ObjectSpace
277
255
  #
278
256
  # If *shapes* is a positive integer, only shapes newer than the provided shape
279
257
  # id are dumped. The current shape_id can be accessed using
280
- # `RubyVM.stat(:next_shape_id)`.
258
+ # <code>RubyVM.stat(:next_shape_id)</code>.
281
259
  #
282
260
  # If *shapes* is `false`, no shapes are dumped.
283
261
  #
@@ -9,9 +9,9 @@ module URI
9
9
  # If the first argument responds to the 'open' method, 'open' is called on it
10
10
  # with the rest of the arguments.
11
11
  #
12
- # If the first argument is a string that begins with `(protocol)://`, it is
13
- # parsed by URI.parse. If the parsed object responds to the 'open' method,
14
- # 'open' is called on it with the rest of the arguments.
12
+ # If the first argument is a string that begins with <code>(protocol)://</code>,
13
+ # it is parsed by URI.parse. If the parsed object responds to the 'open'
14
+ # method, 'open' is called on it with the rest of the arguments.
15
15
  #
16
16
  # Otherwise, Kernel#open is called.
17
17
  #
@@ -349,17 +349,17 @@ module OpenURI
349
349
  # : Synopsis:
350
350
  # :ftp_active_mode=>bool
351
351
  #
352
- # `:ftp_active_mode => true` is used to make ftp active mode. Ruby 1.9 uses
353
- # passive mode by default. Note that the active mode is default in Ruby 1.8
354
- # or prior.
352
+ # <code>:ftp_active_mode => true</code> is used to make ftp active mode.
353
+ # Ruby 1.9 uses passive mode by default. Note that the active mode is
354
+ # default in Ruby 1.8 or prior.
355
355
  #
356
356
  #
357
357
  # :redirect
358
358
  # : Synopsis:
359
359
  # :redirect=>bool
360
360
  #
361
- # `:redirect` is true by default. `:redirect => false` is used to disable
362
- # all HTTP redirects.
361
+ # <code>:redirect</code> is true by default. <code>:redirect =>
362
+ # false</code> is used to disable all HTTP redirects.
363
363
  #
364
364
  # OpenURI::HTTPRedirect exception raised on redirection. Using `true` also
365
365
  # means that redirections between http and ftp are permitted.
@@ -48,6 +48,106 @@
48
48
  # Options](rdoc-ref:Process@Execution+Options).
49
49
  #
50
50
  module Open3
51
+ type env = Hash[String, String]
52
+
53
+ # <!--
54
+ # rdoc-file=lib/open3.rb
55
+ # - Open3.capture2([env, ] command_line, options = {}) -> [stdout_s, status]
56
+ # - Open3.capture2([env, ] exe_path, *args, options = {}) -> [stdout_s, status]
57
+ # -->
58
+ # Basically a wrapper for Open3.popen3 that:
59
+ #
60
+ # * Creates a child process, by calling Open3.popen3 with the given arguments
61
+ # (except for certain entries in hash `options`; see below).
62
+ # * Returns as string `stdout_s` the standard output of the child process.
63
+ # * Returns as `status` a <code>Process::Status</code> object that represents
64
+ # the exit status of the child process.
65
+ #
66
+ # Returns the array <code>[stdout_s, status]</code>:
67
+ #
68
+ # stdout_s, status = Open3.capture2('echo "Foo"')
69
+ # # => ["Foo\n", #<Process::Status: pid 2326047 exit 0>]
70
+ #
71
+ # Like Process.spawn, this method has potential security vulnerabilities if
72
+ # called with untrusted input; see [Command
73
+ # Injection](rdoc-ref:command_injection.rdoc@Command+Injection).
74
+ #
75
+ # Unlike Process.spawn, this method waits for the child process to exit before
76
+ # returning, so the caller need not do so.
77
+ #
78
+ # If the first argument is a hash, it becomes leading argument `env` in the call
79
+ # to Open3.popen3; see [Execution
80
+ # Environment](rdoc-ref:Process@Execution+Environment).
81
+ #
82
+ # If the last argument is a hash, it becomes trailing argument `options` in the
83
+ # call to Open3.popen3; see [Execution
84
+ # Options](rdoc-ref:Process@Execution+Options).
85
+ #
86
+ # The hash `options` is given; two options have local effect in method
87
+ # Open3.capture2:
88
+ #
89
+ # * If entry <code>options[:stdin_data]</code> exists, the entry is removed
90
+ # and its string value is sent to the command's standard input:
91
+ #
92
+ # Open3.capture2('tee', stdin_data: 'Foo')
93
+ #
94
+ # # => ["Foo", #<Process::Status: pid 2326087 exit 0>]
95
+ #
96
+ # * If entry <code>options[:binmode]</code> exists, the entry is removed and
97
+ # the internal streams are set to binary mode.
98
+ #
99
+ # The single required argument is one of the following:
100
+ #
101
+ # * `command_line` if it is a string, and if it begins with a shell reserved
102
+ # word or special built-in, or if it contains one or more metacharacters.
103
+ # * `exe_path` otherwise.
104
+ #
105
+ # <strong>Argument `command_line`</strong>
106
+ #
107
+ # String argument `command_line` is a command line to be passed to a shell; it
108
+ # must begin with a shell reserved word, begin with a special built-in, or
109
+ # contain meta characters:
110
+ #
111
+ # Open3.capture2('if true; then echo "Foo"; fi') # Shell reserved word.
112
+ # # => ["Foo\n", #<Process::Status: pid 2326131 exit 0>]
113
+ # Open3.capture2('echo') # Built-in.
114
+ # # => ["\n", #<Process::Status: pid 2326139 exit 0>]
115
+ # Open3.capture2('date > date.tmp') # Contains meta character.
116
+ # # => ["", #<Process::Status: pid 2326174 exit 0>]
117
+ #
118
+ # The command line may also contain arguments and options for the command:
119
+ #
120
+ # Open3.capture2('echo "Foo"')
121
+ # # => ["Foo\n", #<Process::Status: pid 2326183 exit 0>]
122
+ #
123
+ # <strong>Argument `exe_path`</strong>
124
+ #
125
+ # Argument `exe_path` is one of the following:
126
+ #
127
+ # * The string path to an executable to be called.
128
+ # * A 2-element array containing the path to an executable and the string to
129
+ # be used as the name of the executing process.
130
+ #
131
+ # Example:
132
+ #
133
+ # Open3.capture2('/usr/bin/date')
134
+ # # => ["Fri Sep 29 01:00:39 PM CDT 2023\n", #<Process::Status: pid 2326222 exit 0>]
135
+ #
136
+ # Ruby invokes the executable directly, with no shell and no shell expansion:
137
+ #
138
+ # Open3.capture2('doesnt_exist') # Raises Errno::ENOENT
139
+ #
140
+ # If one or more `args` is given, each is an argument or option to be passed to
141
+ # the executable:
142
+ #
143
+ # Open3.capture2('echo', 'C #')
144
+ # # => ["C #\n", #<Process::Status: pid 2326267 exit 0>]
145
+ # Open3.capture2('echo', 'hello', 'world')
146
+ # # => ["hello world\n", #<Process::Status: pid 2326299 exit 0>]
147
+ #
148
+ def self?.capture2: (*String, ?stdin_data: String, ?binmode: boolish) -> [String, Process::Status]
149
+ | (env, *String, ?stdin_data: String, ?binmode: boolish) -> [String, Process::Status]
150
+
51
151
  # <!--
52
152
  # rdoc-file=lib/open3.rb
53
153
  # - Open3.capture2e([env, ] command_line, options = {}) -> [stdout_and_stderr_s, status]
@@ -59,10 +159,10 @@ module Open3
59
159
  # (except for certain entries in hash `options`; see below).
60
160
  # * Returns as string `stdout_and_stderr_s` the merged standard output and
61
161
  # standard error of the child process.
62
- # * Returns as `status` a `Process::Status` object that represents the exit
63
- # status of the child process.
162
+ # * Returns as `status` a <code>Process::Status</code> object that represents
163
+ # the exit status of the child process.
64
164
  #
65
- # Returns the array `[stdout_and_stderr_s, status]`:
165
+ # Returns the array <code>[stdout_and_stderr_s, status]</code>:
66
166
  #
67
167
  # stdout_and_stderr_s, status = Open3.capture2e('echo "Foo"')
68
168
  # # => ["Foo\n", #<Process::Status: pid 2371692 exit 0>]
@@ -85,14 +185,14 @@ module Open3
85
185
  # The hash `options` is given; two options have local effect in method
86
186
  # Open3.capture2e:
87
187
  #
88
- # * If entry `options[:stdin_data]` exists, the entry is removed and its
89
- # string value is sent to the command's standard input:
188
+ # * If entry <code>options[:stdin_data]</code> exists, the entry is removed
189
+ # and its string value is sent to the command's standard input:
90
190
  #
91
191
  # Open3.capture2e('tee', stdin_data: 'Foo')
92
192
  # # => ["Foo", #<Process::Status: pid 2371732 exit 0>]
93
193
  #
94
- # * If entry `options[:binmode]` exists, the entry is removed and the internal
95
- # streams are set to binary mode.
194
+ # * If entry <code>options[:binmode]</code> exists, the entry is removed and
195
+ # the internal streams are set to binary mode.
96
196
  #
97
197
  # The single required argument is one of the following:
98
198
  #
@@ -100,7 +200,7 @@ module Open3
100
200
  # word or special built-in, or if it contains one or more metacharacters.
101
201
  # * `exe_path` otherwise.
102
202
  #
103
- # **Argument `command_line`**
203
+ # <strong>Argument `command_line`</strong>
104
204
  #
105
205
  # String argument `command_line` is a command line to be passed to a shell; it
106
206
  # must begin with a shell reserved word, begin with a special built-in, or
@@ -118,7 +218,7 @@ module Open3
118
218
  # Open3.capture2e('echo "Foo"')
119
219
  # # => ["Foo\n", #<Process::Status: pid 2326183 exit 0>]
120
220
  #
121
- # **Argument `exe_path`**
221
+ # <strong>Argument `exe_path`</strong>
122
222
  #
123
223
  # Argument `exe_path` is one of the following:
124
224
  #
@@ -143,5 +243,364 @@ module Open3
143
243
  # Open3.capture2e('echo', 'hello', 'world')
144
244
  # # => ["hello world\n", #<Process::Status: pid 2371894 exit 0>]
145
245
  #
146
- def self.capture2e: (*String, ?stdin_data: String, ?binmode: boolish) -> [String, Process::Status]
246
+ def self?.capture2e: (*String, ?stdin_data: String, ?binmode: boolish) -> [String, Process::Status]
247
+ | (env, *String, ?stdin_data: String, ?binmode: boolish) -> [String, Process::Status]
248
+
249
+ # <!--
250
+ # rdoc-file=lib/open3.rb
251
+ # - Open3.capture3([env, ] command_line, options = {}) -> [stdout_s, stderr_s, status]
252
+ # - Open3.capture3([env, ] exe_path, *args, options = {}) -> [stdout_s, stderr_s, status]
253
+ # -->
254
+ # Basically a wrapper for Open3.popen3 that:
255
+ #
256
+ # * Creates a child process, by calling Open3.popen3 with the given arguments
257
+ # (except for certain entries in hash `options`; see below).
258
+ # * Returns as strings `stdout_s` and `stderr_s` the standard output and
259
+ # standard error of the child process.
260
+ # * Returns as `status` a <code>Process::Status</code> object that represents
261
+ # the exit status of the child process.
262
+ #
263
+ # Returns the array <code>[stdout_s, stderr_s, status]</code>:
264
+ #
265
+ # stdout_s, stderr_s, status = Open3.capture3('echo "Foo"')
266
+ # # => ["Foo\n", "", #<Process::Status: pid 2281954 exit 0>]
267
+ #
268
+ # Like Process.spawn, this method has potential security vulnerabilities if
269
+ # called with untrusted input; see [Command
270
+ # Injection](rdoc-ref:command_injection.rdoc@Command+Injection).
271
+ #
272
+ # Unlike Process.spawn, this method waits for the child process to exit before
273
+ # returning, so the caller need not do so.
274
+ #
275
+ # If the first argument is a hash, it becomes leading argument `env` in the call
276
+ # to Open3.popen3; see [Execution
277
+ # Environment](rdoc-ref:Process@Execution+Environment).
278
+ #
279
+ # If the last argument is a hash, it becomes trailing argument `options` in the
280
+ # call to Open3.popen3; see [Execution
281
+ # Options](rdoc-ref:Process@Execution+Options).
282
+ #
283
+ # The hash `options` is given; two options have local effect in method
284
+ # Open3.capture3:
285
+ #
286
+ # * If entry <code>options[:stdin_data]</code> exists, the entry is removed
287
+ # and its string value is sent to the command's standard input:
288
+ #
289
+ # Open3.capture3('tee', stdin_data: 'Foo')
290
+ # # => ["Foo", "", #<Process::Status: pid 2319575 exit 0>]
291
+ #
292
+ # * If entry <code>options[:binmode]</code> exists, the entry is removed and
293
+ # the internal streams are set to binary mode.
294
+ #
295
+ # The single required argument is one of the following:
296
+ #
297
+ # * `command_line` if it is a string, and if it begins with a shell reserved
298
+ # word or special built-in, or if it contains one or more metacharacters.
299
+ # * `exe_path` otherwise.
300
+ #
301
+ # <strong>Argument `command_line`</strong>
302
+ #
303
+ # String argument `command_line` is a command line to be passed to a shell; it
304
+ # must begin with a shell reserved word, begin with a special built-in, or
305
+ # contain meta characters:
306
+ #
307
+ # Open3.capture3('if true; then echo "Foo"; fi') # Shell reserved word.
308
+ # # => ["Foo\n", "", #<Process::Status: pid 2282025 exit 0>]
309
+ # Open3.capture3('echo') # Built-in.
310
+ # # => ["\n", "", #<Process::Status: pid 2282092 exit 0>]
311
+ # Open3.capture3('date > date.tmp') # Contains meta character.
312
+ # # => ["", "", #<Process::Status: pid 2282110 exit 0>]
313
+ #
314
+ # The command line may also contain arguments and options for the command:
315
+ #
316
+ # Open3.capture3('echo "Foo"')
317
+ # # => ["Foo\n", "", #<Process::Status: pid 2282092 exit 0>]
318
+ #
319
+ # <strong>Argument `exe_path`</strong>
320
+ #
321
+ # Argument `exe_path` is one of the following:
322
+ #
323
+ # * The string path to an executable to be called.
324
+ # * A 2-element array containing the path to an executable and the string to
325
+ # be used as the name of the executing process.
326
+ #
327
+ # Example:
328
+ #
329
+ # Open3.capture3('/usr/bin/date')
330
+ # # => ["Thu Sep 28 05:03:51 PM CDT 2023\n", "", #<Process::Status: pid 2282300 exit 0>]
331
+ #
332
+ # Ruby invokes the executable directly, with no shell and no shell expansion:
333
+ #
334
+ # Open3.capture3('doesnt_exist') # Raises Errno::ENOENT
335
+ #
336
+ # If one or more `args` is given, each is an argument or option to be passed to
337
+ # the executable:
338
+ #
339
+ # Open3.capture3('echo', 'C #')
340
+ # # => ["C #\n", "", #<Process::Status: pid 2282368 exit 0>]
341
+ # Open3.capture3('echo', 'hello', 'world')
342
+ # # => ["hello world\n", "", #<Process::Status: pid 2282372 exit 0>]
343
+ #
344
+ def self?.capture3: (*String, ?stdin_data: String, ?binmode: boolish) -> [String, String, Process::Status]
345
+ | (env, *String, ?stdin_data: String, ?binmode: boolish) -> [String, String, Process::Status]
346
+
347
+ # <!--
348
+ # rdoc-file=lib/open3.rb
349
+ # - Open3.popen2([env, ] command_line, options = {}) -> [stdin, stdout, wait_thread]
350
+ # - Open3.popen2([env, ] exe_path, *args, options = {}) -> [stdin, stdout, wait_thread]
351
+ # - Open3.popen2([env, ] command_line, options = {}) {|stdin, stdout, wait_thread| ... } -> object
352
+ # - Open3.popen2([env, ] exe_path, *args, options = {}) {|stdin, stdout, wait_thread| ... } -> object
353
+ # -->
354
+ # Basically a wrapper for [Process.spawn](rdoc-ref:Process.spawn) that:
355
+ #
356
+ # * Creates a child process, by calling Process.spawn with the given
357
+ # arguments.
358
+ # * Creates streams `stdin` and `stdout`, which are the standard input and
359
+ # standard output streams in the child process.
360
+ # * Creates thread `wait_thread` that waits for the child process to exit; the
361
+ # thread has method `pid`, which returns the process ID of the child
362
+ # process.
363
+ #
364
+ # With no block given, returns the array <code>[stdin, stdout,
365
+ # wait_thread]</code>. The caller should close each of the two returned streams.
366
+ #
367
+ # stdin, stdout, wait_thread = Open3.popen2('echo')
368
+ # # => [#<IO:fd 6>, #<IO:fd 7>, #<Process::Waiter:0x00007f58d52dbe98 run>]
369
+ # stdin.close
370
+ # stdout.close
371
+ # wait_thread.pid # => 2263572
372
+ # wait_thread.value # => #<Process::Status: pid 2263572 exit 0>
373
+ #
374
+ # With a block given, calls the block with the three variables (two streams and
375
+ # the wait thread) and returns the block's return value. The caller need not
376
+ # close the streams:
377
+ #
378
+ # Open3.popen2('echo') do |stdin, stdout, wait_thread|
379
+ # p stdin
380
+ # p stdout
381
+ # p wait_thread
382
+ # p wait_thread.pid
383
+ # p wait_thread.value
384
+ # end
385
+ #
386
+ # Output:
387
+ #
388
+ # #<IO:fd 6>
389
+ # #<IO:fd 7>
390
+ # #<Process::Waiter:0x00007f58d59a34b0 sleep>
391
+ # 2263636
392
+ # #<Process::Status: pid 2263636 exit 0>
393
+ #
394
+ # Like Process.spawn, this method has potential security vulnerabilities if
395
+ # called with untrusted input; see [Command
396
+ # Injection](rdoc-ref:command_injection.rdoc@Command+Injection).
397
+ #
398
+ # Unlike Process.spawn, this method waits for the child process to exit before
399
+ # returning, so the caller need not do so.
400
+ #
401
+ # If the first argument is a hash, it becomes leading argument `env` in the call
402
+ # to Process.spawn; see [Execution
403
+ # Environment](rdoc-ref:Process@Execution+Environment).
404
+ #
405
+ # If the last argument is a hash, it becomes trailing argument `options` in the
406
+ # call to Process.spawn; see [Execution
407
+ # Options](rdoc-ref:Process@Execution+Options).
408
+ #
409
+ # The single required argument is one of the following:
410
+ #
411
+ # * `command_line` if it is a string, and if it begins with a shell reserved
412
+ # word or special built-in, or if it contains one or more metacharacters.
413
+ # * `exe_path` otherwise.
414
+ #
415
+ # <strong>Argument `command_line`</strong>
416
+ #
417
+ # String argument `command_line` is a command line to be passed to a shell; it
418
+ # must begin with a shell reserved word, begin with a special built-in, or
419
+ # contain meta characters:
420
+ #
421
+ # Open3.popen2('if true; then echo "Foo"; fi') {|*args| p args } # Shell reserved word.
422
+ # Open3.popen2('echo') {|*args| p args } # Built-in.
423
+ # Open3.popen2('date > date.tmp') {|*args| p args } # Contains meta character.
424
+ #
425
+ # Output (similar for each call above):
426
+ #
427
+ # # => [#<IO:(closed)>, #<IO:(closed)>, #<Process::Waiter:0x00007f7577dfe410 dead>]
428
+ #
429
+ # The command line may also contain arguments and options for the command:
430
+ #
431
+ # Open3.popen2('echo "Foo"') { |i, o, t| o.gets }
432
+ # "Foo\n"
433
+ #
434
+ # <strong>Argument `exe_path`</strong>
435
+ #
436
+ # Argument `exe_path` is one of the following:
437
+ #
438
+ # * The string path to an executable to be called.
439
+ # * A 2-element array containing the path to an executable and the string to
440
+ # be used as the name of the executing process.
441
+ #
442
+ # Example:
443
+ #
444
+ # Open3.popen2('/usr/bin/date') { |i, o, t| o.gets }
445
+ # # => "Thu Sep 28 09:41:06 AM CDT 2023\n"
446
+ #
447
+ # Ruby invokes the executable directly, with no shell and no shell expansion:
448
+ #
449
+ # Open3.popen2('doesnt_exist') { |i, o, t| o.gets } # Raises Errno::ENOENT
450
+ #
451
+ # If one or more `args` is given, each is an argument or option to be passed to
452
+ # the executable:
453
+ #
454
+ # Open3.popen2('echo', 'C #') { |i, o, t| o.gets }
455
+ # # => "C #\n"
456
+ # Open3.popen2('echo', 'hello', 'world') { |i, o, t| o.gets }
457
+ # # => "hello world\n"
458
+ #
459
+ # Related:
460
+ #
461
+ # * Open3.popen2e: Makes the standard input and the merge of the standard
462
+ # output and standard error streams of the child process available as
463
+ # separate streams.
464
+ # * Open3.popen3: Makes the standard input, standard output, and standard
465
+ # error streams of the child process available as separate streams.
466
+ #
467
+ def self?.popen2: (*String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) -> [IO, IO, Process::Waiter]
468
+ | (env, *String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) -> [IO, IO, Process::Waiter]
469
+ | [T] (*String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) { (IO, IO, Process::Waiter) -> T } -> T
470
+ | [T] (env, *String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) { (IO, IO, Process::Waiter) -> T } -> T
471
+
472
+ # <!--
473
+ # rdoc-file=lib/open3.rb
474
+ # - Open3.popen3([env, ] command_line, options = {}) -> [stdin, stdout, stderr, wait_thread]
475
+ # - Open3.popen3([env, ] exe_path, *args, options = {}) -> [stdin, stdout, stderr, wait_thread]
476
+ # - Open3.popen3([env, ] command_line, options = {}) {|stdin, stdout, stderr, wait_thread| ... } -> object
477
+ # - Open3.popen3([env, ] exe_path, *args, options = {}) {|stdin, stdout, stderr, wait_thread| ... } -> object
478
+ # -->
479
+ # Basically a wrapper for [Process.spawn](rdoc-ref:Process.spawn) that:
480
+ #
481
+ # * Creates a child process, by calling Process.spawn with the given
482
+ # arguments.
483
+ # * Creates streams `stdin`, `stdout`, and `stderr`, which are the standard
484
+ # input, standard output, and standard error streams in the child process.
485
+ # * Creates thread `wait_thread` that waits for the child process to exit; the
486
+ # thread has method `pid`, which returns the process ID of the child
487
+ # process.
488
+ #
489
+ # With no block given, returns the array <code>[stdin, stdout, stderr,
490
+ # wait_thread]</code>. The caller should close each of the three returned
491
+ # streams.
492
+ #
493
+ # stdin, stdout, stderr, wait_thread = Open3.popen3('echo')
494
+ # # => [#<IO:fd 8>, #<IO:fd 10>, #<IO:fd 12>, #<Process::Waiter:0x00007f58d5428f58 run>]
495
+ # stdin.close
496
+ # stdout.close
497
+ # stderr.close
498
+ # wait_thread.pid # => 2210481
499
+ # wait_thread.value # => #<Process::Status: pid 2210481 exit 0>
500
+ #
501
+ # With a block given, calls the block with the four variables (three streams and
502
+ # the wait thread) and returns the block's return value. The caller need not
503
+ # close the streams:
504
+ #
505
+ # Open3.popen3('echo') do |stdin, stdout, stderr, wait_thread|
506
+ # p stdin
507
+ # p stdout
508
+ # p stderr
509
+ # p wait_thread
510
+ # p wait_thread.pid
511
+ # p wait_thread.value
512
+ # end
513
+ #
514
+ # Output:
515
+ #
516
+ # #<IO:fd 6>
517
+ # #<IO:fd 7>
518
+ # #<IO:fd 9>
519
+ # #<Process::Waiter:0x00007f58d53606e8 sleep>
520
+ # 2211047
521
+ # #<Process::Status: pid 2211047 exit 0>
522
+ #
523
+ # Like Process.spawn, this method has potential security vulnerabilities if
524
+ # called with untrusted input; see [Command
525
+ # Injection](rdoc-ref:command_injection.rdoc@Command+Injection).
526
+ #
527
+ # Unlike Process.spawn, this method waits for the child process to exit before
528
+ # returning, so the caller need not do so.
529
+ #
530
+ # If the first argument is a hash, it becomes leading argument `env` in the call
531
+ # to Process.spawn; see [Execution
532
+ # Environment](rdoc-ref:Process@Execution+Environment).
533
+ #
534
+ # If the last argument is a hash, it becomes trailing argument `options` in the
535
+ # call to Process.spawn; see [Execution
536
+ # Options](rdoc-ref:Process@Execution+Options).
537
+ #
538
+ # The single required argument is one of the following:
539
+ #
540
+ # * `command_line` if it is a string, and if it begins with a shell reserved
541
+ # word or special built-in, or if it contains one or more metacharacters.
542
+ # * `exe_path` otherwise.
543
+ #
544
+ # <strong>Argument `command_line`</strong>
545
+ #
546
+ # String argument `command_line` is a command line to be passed to a shell; it
547
+ # must begin with a shell reserved word, begin with a special built-in, or
548
+ # contain meta characters:
549
+ #
550
+ # Open3.popen3('if true; then echo "Foo"; fi') {|*args| p args } # Shell reserved word.
551
+ # Open3.popen3('echo') {|*args| p args } # Built-in.
552
+ # Open3.popen3('date > date.tmp') {|*args| p args } # Contains meta character.
553
+ #
554
+ # Output (similar for each call above):
555
+ #
556
+ # [#<IO:(closed)>, #<IO:(closed)>, #<IO:(closed)>, #<Process::Waiter:0x00007f58d52f28c8 dead>]
557
+ #
558
+ # The command line may also contain arguments and options for the command:
559
+ #
560
+ # Open3.popen3('echo "Foo"') { |i, o, e, t| o.gets }
561
+ # "Foo\n"
562
+ #
563
+ # <strong>Argument `exe_path`</strong>
564
+ #
565
+ # Argument `exe_path` is one of the following:
566
+ #
567
+ # * The string path to an executable to be called.
568
+ # * A 2-element array containing the path to an executable and the string to
569
+ # be used as the name of the executing process.
570
+ #
571
+ # Example:
572
+ #
573
+ # Open3.popen3('/usr/bin/date') { |i, o, e, t| o.gets }
574
+ # # => "Wed Sep 27 02:56:44 PM CDT 2023\n"
575
+ #
576
+ # Ruby invokes the executable directly, with no shell and no shell expansion:
577
+ #
578
+ # Open3.popen3('doesnt_exist') { |i, o, e, t| o.gets } # Raises Errno::ENOENT
579
+ #
580
+ # If one or more `args` is given, each is an argument or option to be passed to
581
+ # the executable:
582
+ #
583
+ # Open3.popen3('echo', 'C #') { |i, o, e, t| o.gets }
584
+ # # => "C #\n"
585
+ # Open3.popen3('echo', 'hello', 'world') { |i, o, e, t| o.gets }
586
+ # # => "hello world\n"
587
+ #
588
+ # Take care to avoid deadlocks. Output streams `stdout` and `stderr` have
589
+ # fixed-size buffers, so reading extensively from one but not the other can
590
+ # cause a deadlock when the unread buffer fills. To avoid that, `stdout` and
591
+ # `stderr` should be read simultaneously (using threads or IO.select).
592
+ #
593
+ # Related:
594
+ #
595
+ # * Open3.popen2: Makes the standard input and standard output streams of the
596
+ # child process available as separate streams, with no access to the
597
+ # standard error stream.
598
+ # * Open3.popen2e: Makes the standard input and the merge of the standard
599
+ # output and standard error streams of the child process available as
600
+ # separate streams.
601
+ #
602
+ def self?.popen3: (*String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) -> [IO, IO, IO, Process::Waiter]
603
+ | (env, *String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) -> [IO, IO, IO, Process::Waiter]
604
+ | [T] (*String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) { (IO, IO, IO, Process::Waiter) -> T } -> T
605
+ | [T] (env, *String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?close_others: bool, ?chdir: String) { (IO, IO, IO, Process::Waiter) -> T } -> T
147
606
  end