rbs 4.0.0.dev.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 (281) 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 +18 -11
  5. data/.github/workflows/comments.yml +5 -3
  6. data/.github/workflows/dependabot.yml +2 -2
  7. data/.github/workflows/ruby.yml +27 -34
  8. data/.github/workflows/rust.yml +95 -0
  9. data/.github/workflows/typecheck.yml +2 -2
  10. data/.github/workflows/windows.yml +2 -2
  11. data/.rubocop.yml +1 -1
  12. data/CHANGELOG.md +323 -0
  13. data/README.md +1 -1
  14. data/Rakefile +43 -33
  15. data/Steepfile +1 -0
  16. data/config.yml +426 -24
  17. data/core/array.rbs +307 -227
  18. data/core/basic_object.rbs +9 -8
  19. data/core/binding.rbs +0 -2
  20. data/core/builtin.rbs +2 -2
  21. data/core/class.rbs +6 -5
  22. data/core/comparable.rbs +55 -34
  23. data/core/complex.rbs +104 -78
  24. data/core/dir.rbs +61 -49
  25. data/core/encoding.rbs +12 -15
  26. data/core/enumerable.rbs +179 -87
  27. data/core/enumerator/arithmetic_sequence.rbs +70 -0
  28. data/core/enumerator.rbs +65 -2
  29. data/core/errno.rbs +11 -2
  30. data/core/errors.rbs +58 -29
  31. data/core/exception.rbs +13 -13
  32. data/core/fiber.rbs +74 -54
  33. data/core/file.rbs +280 -177
  34. data/core/file_test.rbs +3 -3
  35. data/core/float.rbs +257 -92
  36. data/core/gc.rbs +425 -281
  37. data/core/hash.rbs +1045 -739
  38. data/core/integer.rbs +135 -137
  39. data/core/io/buffer.rbs +53 -42
  40. data/core/io/wait.rbs +13 -35
  41. data/core/io.rbs +192 -144
  42. data/core/kernel.rbs +216 -155
  43. data/core/marshal.rbs +4 -4
  44. data/core/match_data.rbs +15 -13
  45. data/core/math.rbs +107 -66
  46. data/core/method.rbs +69 -33
  47. data/core/module.rbs +244 -106
  48. data/core/nil_class.rbs +7 -6
  49. data/core/numeric.rbs +74 -63
  50. data/core/object.rbs +9 -11
  51. data/core/object_space.rbs +30 -23
  52. data/core/pathname.rbs +1322 -0
  53. data/core/proc.rbs +95 -58
  54. data/core/process.rbs +222 -202
  55. data/core/ractor.rbs +371 -515
  56. data/core/random.rbs +21 -3
  57. data/core/range.rbs +159 -57
  58. data/core/rational.rbs +60 -89
  59. data/core/rbs/unnamed/argf.rbs +60 -53
  60. data/core/rbs/unnamed/env_class.rbs +19 -14
  61. data/core/rbs/unnamed/main_class.rbs +123 -0
  62. data/core/rbs/unnamed/random.rbs +11 -118
  63. data/core/regexp.rbs +258 -214
  64. data/core/ruby.rbs +53 -0
  65. data/core/ruby_vm.rbs +38 -34
  66. data/core/rubygems/config_file.rbs +5 -5
  67. data/core/rubygems/errors.rbs +4 -71
  68. data/core/rubygems/requirement.rbs +5 -5
  69. data/core/rubygems/rubygems.rbs +16 -82
  70. data/core/rubygems/version.rbs +2 -3
  71. data/core/set.rbs +490 -360
  72. data/core/signal.rbs +26 -16
  73. data/core/string.rbs +3234 -1285
  74. data/core/struct.rbs +27 -26
  75. data/core/symbol.rbs +41 -34
  76. data/core/thread.rbs +135 -67
  77. data/core/time.rbs +81 -50
  78. data/core/trace_point.rbs +41 -35
  79. data/core/true_class.rbs +2 -2
  80. data/core/unbound_method.rbs +24 -16
  81. data/core/warning.rbs +7 -7
  82. data/docs/aliases.md +79 -0
  83. data/docs/collection.md +3 -3
  84. data/docs/config.md +171 -0
  85. data/docs/encoding.md +56 -0
  86. data/docs/gem.md +0 -1
  87. data/docs/inline.md +576 -0
  88. data/docs/sigs.md +3 -3
  89. data/docs/syntax.md +46 -16
  90. data/docs/type_fingerprint.md +21 -0
  91. data/exe/rbs +1 -1
  92. data/ext/rbs_extension/ast_translation.c +544 -116
  93. data/ext/rbs_extension/ast_translation.h +3 -0
  94. data/ext/rbs_extension/class_constants.c +16 -2
  95. data/ext/rbs_extension/class_constants.h +8 -0
  96. data/ext/rbs_extension/extconf.rb +5 -1
  97. data/ext/rbs_extension/legacy_location.c +33 -56
  98. data/ext/rbs_extension/legacy_location.h +37 -0
  99. data/ext/rbs_extension/main.c +44 -35
  100. data/include/rbs/ast.h +448 -173
  101. data/include/rbs/defines.h +27 -0
  102. data/include/rbs/lexer.h +30 -11
  103. data/include/rbs/location.h +25 -44
  104. data/include/rbs/parser.h +6 -6
  105. data/include/rbs/string.h +0 -2
  106. data/include/rbs/util/rbs_allocator.h +34 -13
  107. data/include/rbs/util/rbs_assert.h +12 -1
  108. data/include/rbs/util/rbs_constant_pool.h +0 -3
  109. data/include/rbs/util/rbs_encoding.h +2 -0
  110. data/include/rbs/util/rbs_unescape.h +2 -1
  111. data/include/rbs.h +8 -0
  112. data/lib/rbs/ast/annotation.rb +1 -1
  113. data/lib/rbs/ast/comment.rb +1 -1
  114. data/lib/rbs/ast/declarations.rb +10 -10
  115. data/lib/rbs/ast/members.rb +14 -14
  116. data/lib/rbs/ast/ruby/annotations.rb +293 -3
  117. data/lib/rbs/ast/ruby/comment_block.rb +24 -0
  118. data/lib/rbs/ast/ruby/declarations.rb +198 -3
  119. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
  120. data/lib/rbs/ast/ruby/members.rb +532 -22
  121. data/lib/rbs/ast/type_param.rb +24 -4
  122. data/lib/rbs/buffer.rb +20 -15
  123. data/lib/rbs/cli/diff.rb +16 -15
  124. data/lib/rbs/cli/validate.rb +38 -106
  125. data/lib/rbs/cli.rb +52 -19
  126. data/lib/rbs/collection/config/lockfile_generator.rb +14 -2
  127. data/lib/rbs/collection/sources/git.rb +1 -0
  128. data/lib/rbs/definition.rb +1 -1
  129. data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
  130. data/lib/rbs/definition_builder/method_builder.rb +20 -0
  131. data/lib/rbs/definition_builder.rb +147 -25
  132. data/lib/rbs/diff.rb +7 -1
  133. data/lib/rbs/environment.rb +227 -74
  134. data/lib/rbs/environment_loader.rb +0 -6
  135. data/lib/rbs/errors.rb +27 -18
  136. data/lib/rbs/inline_parser.rb +342 -6
  137. data/lib/rbs/location_aux.rb +1 -1
  138. data/lib/rbs/locator.rb +5 -1
  139. data/lib/rbs/method_type.rb +5 -3
  140. data/lib/rbs/parser_aux.rb +20 -7
  141. data/lib/rbs/prototype/helpers.rb +57 -0
  142. data/lib/rbs/prototype/rb.rb +3 -28
  143. data/lib/rbs/prototype/rbi.rb +3 -20
  144. data/lib/rbs/prototype/runtime.rb +8 -0
  145. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  146. data/lib/rbs/resolver/type_name_resolver.rb +116 -38
  147. data/lib/rbs/subtractor.rb +3 -1
  148. data/lib/rbs/test/type_check.rb +19 -2
  149. data/lib/rbs/type_name.rb +1 -1
  150. data/lib/rbs/types.rb +88 -78
  151. data/lib/rbs/unit_test/type_assertions.rb +35 -8
  152. data/lib/rbs/validator.rb +2 -2
  153. data/lib/rbs/version.rb +1 -1
  154. data/lib/rbs.rb +1 -2
  155. data/lib/rdoc/discover.rb +1 -1
  156. data/lib/rdoc_plugin/parser.rb +1 -1
  157. data/rbs.gemspec +4 -3
  158. data/rust/.gitignore +1 -0
  159. data/rust/Cargo.lock +378 -0
  160. data/rust/Cargo.toml +7 -0
  161. data/rust/ruby-rbs/Cargo.toml +22 -0
  162. data/rust/ruby-rbs/build.rs +764 -0
  163. data/rust/ruby-rbs/examples/locations.rs +60 -0
  164. data/rust/ruby-rbs/src/lib.rs +1 -0
  165. data/rust/ruby-rbs/src/node/mod.rs +742 -0
  166. data/rust/ruby-rbs/tests/sanity.rs +47 -0
  167. data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
  168. data/rust/ruby-rbs-sys/Cargo.toml +23 -0
  169. data/rust/ruby-rbs-sys/build.rs +204 -0
  170. data/rust/ruby-rbs-sys/src/lib.rs +50 -0
  171. data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
  172. data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
  173. data/rust/ruby-rbs-sys/wrapper.h +1 -0
  174. data/schema/typeParam.json +17 -1
  175. data/sig/ast/ruby/annotations.rbs +315 -4
  176. data/sig/ast/ruby/comment_block.rbs +8 -0
  177. data/sig/ast/ruby/declarations.rbs +102 -4
  178. data/sig/ast/ruby/members.rbs +108 -2
  179. data/sig/cli/diff.rbs +5 -11
  180. data/sig/cli/validate.rbs +12 -8
  181. data/sig/cli.rbs +18 -18
  182. data/sig/definition.rbs +6 -1
  183. data/sig/definition_builder.rbs +2 -0
  184. data/sig/environment.rbs +70 -12
  185. data/sig/errors.rbs +13 -14
  186. data/sig/inline_parser.rbs +39 -2
  187. data/sig/locator.rbs +0 -2
  188. data/sig/manifest.yaml +0 -1
  189. data/sig/method_builder.rbs +3 -1
  190. data/sig/parser.rbs +31 -13
  191. data/sig/prototype/helpers.rbs +2 -0
  192. data/sig/resolver/type_name_resolver.rbs +35 -7
  193. data/sig/source.rbs +3 -3
  194. data/sig/type_param.rbs +13 -8
  195. data/sig/types.rbs +6 -7
  196. data/sig/unit_test/spy.rbs +0 -8
  197. data/sig/unit_test/type_assertions.rbs +11 -0
  198. data/src/ast.c +410 -153
  199. data/src/lexer.c +1392 -1313
  200. data/src/lexer.re +3 -0
  201. data/src/lexstate.c +58 -37
  202. data/src/location.c +8 -48
  203. data/src/parser.c +977 -516
  204. data/src/string.c +0 -48
  205. data/src/util/rbs_allocator.c +89 -71
  206. data/src/util/rbs_assert.c +1 -1
  207. data/src/util/rbs_buffer.c +2 -2
  208. data/src/util/rbs_constant_pool.c +10 -14
  209. data/src/util/rbs_encoding.c +4 -8
  210. data/src/util/rbs_unescape.c +56 -20
  211. data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
  212. data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
  213. data/stdlib/cgi/0/core.rbs +9 -393
  214. data/stdlib/cgi/0/manifest.yaml +1 -0
  215. data/stdlib/cgi-escape/0/escape.rbs +171 -0
  216. data/stdlib/coverage/0/coverage.rbs +7 -4
  217. data/stdlib/date/0/date.rbs +92 -79
  218. data/stdlib/date/0/date_time.rbs +25 -24
  219. data/stdlib/delegate/0/delegator.rbs +10 -7
  220. data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
  221. data/stdlib/digest/0/digest.rbs +110 -0
  222. data/stdlib/erb/0/erb.rbs +748 -347
  223. data/stdlib/etc/0/etc.rbs +55 -50
  224. data/stdlib/fileutils/0/fileutils.rbs +158 -139
  225. data/stdlib/forwardable/0/forwardable.rbs +13 -10
  226. data/stdlib/io-console/0/io-console.rbs +2 -2
  227. data/stdlib/json/0/json.rbs +217 -136
  228. data/stdlib/monitor/0/monitor.rbs +3 -3
  229. data/stdlib/net-http/0/net-http.rbs +162 -134
  230. data/stdlib/objspace/0/objspace.rbs +17 -34
  231. data/stdlib/open-uri/0/open-uri.rbs +48 -8
  232. data/stdlib/open3/0/open3.rbs +469 -10
  233. data/stdlib/openssl/0/openssl.rbs +475 -357
  234. data/stdlib/optparse/0/optparse.rbs +26 -17
  235. data/stdlib/pathname/0/pathname.rbs +11 -1381
  236. data/stdlib/pp/0/pp.rbs +9 -8
  237. data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
  238. data/stdlib/pstore/0/pstore.rbs +35 -30
  239. data/stdlib/psych/0/psych.rbs +65 -12
  240. data/stdlib/psych/0/store.rbs +2 -4
  241. data/stdlib/pty/0/pty.rbs +9 -6
  242. data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
  243. data/stdlib/rdoc/0/code_object.rbs +2 -1
  244. data/stdlib/rdoc/0/parser.rbs +1 -1
  245. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  246. data/stdlib/rdoc/0/store.rbs +1 -1
  247. data/stdlib/resolv/0/resolv.rbs +25 -68
  248. data/stdlib/ripper/0/ripper.rbs +22 -19
  249. data/stdlib/securerandom/0/manifest.yaml +2 -0
  250. data/stdlib/securerandom/0/securerandom.rbs +7 -20
  251. data/stdlib/shellwords/0/shellwords.rbs +2 -2
  252. data/stdlib/singleton/0/singleton.rbs +3 -0
  253. data/stdlib/socket/0/addrinfo.rbs +7 -7
  254. data/stdlib/socket/0/basic_socket.rbs +3 -3
  255. data/stdlib/socket/0/ip_socket.rbs +10 -8
  256. data/stdlib/socket/0/socket.rbs +23 -10
  257. data/stdlib/socket/0/tcp_server.rbs +1 -1
  258. data/stdlib/socket/0/tcp_socket.rbs +11 -3
  259. data/stdlib/socket/0/udp_socket.rbs +1 -1
  260. data/stdlib/socket/0/unix_server.rbs +1 -1
  261. data/stdlib/stringio/0/stringio.rbs +1177 -85
  262. data/stdlib/strscan/0/string_scanner.rbs +27 -25
  263. data/stdlib/tempfile/0/tempfile.rbs +25 -21
  264. data/stdlib/time/0/time.rbs +8 -6
  265. data/stdlib/timeout/0/timeout.rbs +63 -7
  266. data/stdlib/tsort/0/cyclic.rbs +3 -0
  267. data/stdlib/tsort/0/tsort.rbs +7 -6
  268. data/stdlib/uri/0/common.rbs +42 -20
  269. data/stdlib/uri/0/file.rbs +3 -3
  270. data/stdlib/uri/0/generic.rbs +26 -18
  271. data/stdlib/uri/0/http.rbs +2 -2
  272. data/stdlib/uri/0/ldap.rbs +2 -2
  273. data/stdlib/uri/0/mailto.rbs +3 -3
  274. data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
  275. data/stdlib/zlib/0/deflate.rbs +4 -3
  276. data/stdlib/zlib/0/gzip_reader.rbs +6 -6
  277. data/stdlib/zlib/0/gzip_writer.rbs +14 -12
  278. data/stdlib/zlib/0/inflate.rbs +1 -1
  279. data/stdlib/zlib/0/need_dict.rbs +1 -1
  280. data/stdlib/zlib/0/zstream.rbs +1 -0
  281. metadata +50 -6
@@ -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