rbs 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (179) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ruby.yml +5 -0
  3. data/CHANGELOG.md +23 -0
  4. data/README.md +6 -1
  5. data/core/array.rbs +2866 -1086
  6. data/core/basic_object.rbs +150 -30
  7. data/core/binding.rbs +33 -0
  8. data/core/builtin.rbs +4 -4
  9. data/core/class.rbs +43 -5
  10. data/core/comparable.rbs +57 -0
  11. data/core/complex.rbs +170 -4
  12. data/core/constants.rbs +51 -0
  13. data/core/deprecated.rbs +7 -0
  14. data/core/dir.rbs +305 -20
  15. data/core/encoding.rbs +472 -77
  16. data/core/enumerable.rbs +2173 -234
  17. data/core/enumerator.rbs +448 -182
  18. data/core/env.rbs +448 -1
  19. data/core/errno.rbs +1 -10
  20. data/core/errors.rbs +152 -2
  21. data/core/exception.rbs +201 -127
  22. data/core/false_class.rbs +27 -0
  23. data/core/fiber.rbs +118 -37
  24. data/core/fiber_error.rbs +8 -9
  25. data/core/file.rbs +1059 -139
  26. data/core/file_test.rbs +287 -32
  27. data/core/float.rbs +776 -300
  28. data/core/gc.rbs +185 -34
  29. data/core/global_variables.rbs +5 -1
  30. data/core/hash.rbs +1582 -649
  31. data/core/integer.rbs +974 -204
  32. data/core/io/buffer.rbs +710 -0
  33. data/core/io/wait.rbs +29 -8
  34. data/core/io.rbs +2438 -417
  35. data/core/kernel.rbs +2315 -316
  36. data/core/marshal.rbs +37 -2
  37. data/core/match_data.rbs +123 -6
  38. data/core/math.rbs +126 -6
  39. data/core/method.rbs +226 -102
  40. data/core/module.rbs +421 -45
  41. data/core/nil_class.rbs +64 -0
  42. data/core/numeric.rbs +620 -142
  43. data/core/object.rbs +453 -81
  44. data/core/object_space.rbs +92 -2
  45. data/core/proc.rbs +482 -285
  46. data/core/process.rbs +443 -34
  47. data/core/ractor.rbs +232 -9
  48. data/core/random.rbs +151 -52
  49. data/core/range.rbs +885 -160
  50. data/core/rational.rbs +122 -6
  51. data/core/rb_config.rbs +14 -4
  52. data/core/refinement.rbs +44 -0
  53. data/core/regexp.rbs +156 -14
  54. data/core/ruby_vm.rbs +42 -3
  55. data/core/signal.rbs +78 -39
  56. data/core/string.rbs +2123 -567
  57. data/core/string_io.rbs +204 -0
  58. data/core/struct.rbs +283 -28
  59. data/core/symbol.rbs +304 -30
  60. data/core/thread.rbs +1288 -688
  61. data/core/thread_group.rbs +66 -10
  62. data/core/time.rbs +643 -217
  63. data/core/trace_point.rbs +100 -12
  64. data/core/true_class.rbs +24 -0
  65. data/core/unbound_method.rbs +73 -7
  66. data/core/warning.rbs +37 -12
  67. data/docs/CONTRIBUTING.md +40 -34
  68. data/docs/stdlib.md +3 -102
  69. data/lib/rbs/annotate/annotations.rb +197 -0
  70. data/lib/rbs/annotate/formatter.rb +80 -0
  71. data/lib/rbs/annotate/rdoc_annotator.rb +398 -0
  72. data/lib/rbs/annotate/rdoc_source.rb +120 -0
  73. data/lib/rbs/annotate.rb +6 -0
  74. data/lib/rbs/cli.rb +45 -1
  75. data/lib/rbs/definition_builder.rb +5 -1
  76. data/lib/rbs/location_aux.rb +12 -0
  77. data/lib/rbs/prototype/rb.rb +12 -0
  78. data/lib/rbs/version.rb +1 -1
  79. data/sig/annotate/annotations.rbs +102 -0
  80. data/sig/annotate/formatter.rbs +24 -0
  81. data/sig/annotate/rdoc_annotater.rbs +82 -0
  82. data/sig/annotate/rdoc_source.rbs +30 -0
  83. data/sig/cli.rbs +2 -0
  84. data/sig/collection/{collections.rbs → sources.rbs} +0 -0
  85. data/sig/location.rbs +6 -0
  86. data/sig/method_types.rbs +5 -1
  87. data/sig/polyfill.rbs +78 -0
  88. data/stdlib/abbrev/0/abbrev.rbs +6 -0
  89. data/stdlib/abbrev/0/array.rbs +26 -0
  90. data/stdlib/base64/0/base64.rbs +31 -0
  91. data/stdlib/benchmark/0/benchmark.rbs +74 -3
  92. data/stdlib/bigdecimal/0/big_decimal.rbs +614 -165
  93. data/stdlib/bigdecimal-math/0/big_math.rbs +41 -64
  94. data/stdlib/cgi/0/core.rbs +59 -0
  95. data/stdlib/coverage/0/coverage.rbs +164 -2
  96. data/stdlib/csv/0/csv.rbs +2862 -398
  97. data/stdlib/date/0/date.rbs +483 -25
  98. data/stdlib/date/0/date_time.rbs +187 -12
  99. data/stdlib/dbm/0/dbm.rbs +152 -17
  100. data/stdlib/digest/0/digest.rbs +146 -0
  101. data/stdlib/erb/0/erb.rbs +65 -245
  102. data/stdlib/fiber/0/fiber.rbs +73 -91
  103. data/stdlib/fileutils/0/fileutils.rbs +301 -1
  104. data/stdlib/find/0/find.rbs +9 -0
  105. data/stdlib/forwardable/0/forwardable.rbs +65 -1
  106. data/stdlib/io-console/0/io-console.rbs +227 -15
  107. data/stdlib/ipaddr/0/ipaddr.rbs +161 -0
  108. data/stdlib/json/0/json.rbs +1146 -144
  109. data/stdlib/logger/0/formatter.rbs +24 -0
  110. data/stdlib/logger/0/log_device.rbs +64 -0
  111. data/stdlib/logger/0/logger.rbs +165 -13
  112. data/stdlib/logger/0/period.rbs +10 -0
  113. data/stdlib/logger/0/severity.rbs +26 -0
  114. data/stdlib/monitor/0/monitor.rbs +163 -0
  115. data/stdlib/mutex_m/0/mutex_m.rbs +35 -6
  116. data/stdlib/net-http/0/net-http.rbs +1492 -683
  117. data/stdlib/nkf/0/nkf.rbs +372 -0
  118. data/stdlib/objspace/0/objspace.rbs +149 -90
  119. data/stdlib/openssl/0/openssl.rbs +8108 -71
  120. data/stdlib/optparse/0/optparse.rbs +487 -19
  121. data/stdlib/pathname/0/pathname.rbs +425 -124
  122. data/stdlib/prettyprint/0/prettyprint.rbs +120 -99
  123. data/stdlib/prime/0/integer-extension.rbs +20 -2
  124. data/stdlib/prime/0/prime.rbs +88 -21
  125. data/stdlib/pstore/0/pstore.rbs +102 -0
  126. data/stdlib/pty/0/pty.rbs +64 -14
  127. data/stdlib/resolv/0/resolv.rbs +420 -31
  128. data/stdlib/rubygems/0/basic_specification.rbs +4 -1
  129. data/stdlib/rubygems/0/config_file.rbs +33 -1
  130. data/stdlib/rubygems/0/dependency_installer.rbs +4 -3
  131. data/stdlib/rubygems/0/installer.rbs +13 -1
  132. data/stdlib/rubygems/0/path_support.rbs +4 -1
  133. data/stdlib/rubygems/0/platform.rbs +5 -1
  134. data/stdlib/rubygems/0/request_set.rbs +44 -2
  135. data/stdlib/rubygems/0/requirement.rbs +65 -2
  136. data/stdlib/rubygems/0/rubygems.rbs +407 -0
  137. data/stdlib/rubygems/0/source_list.rbs +13 -0
  138. data/stdlib/rubygems/0/specification.rbs +21 -1
  139. data/stdlib/rubygems/0/stream_ui.rbs +3 -1
  140. data/stdlib/rubygems/0/uninstaller.rbs +8 -1
  141. data/stdlib/rubygems/0/version.rbs +60 -157
  142. data/stdlib/securerandom/0/securerandom.rbs +44 -0
  143. data/stdlib/set/0/set.rbs +420 -106
  144. data/stdlib/shellwords/0/shellwords.rbs +55 -77
  145. data/stdlib/singleton/0/singleton.rbs +20 -0
  146. data/stdlib/socket/0/addrinfo.rbs +210 -9
  147. data/stdlib/socket/0/basic_socket.rbs +103 -11
  148. data/stdlib/socket/0/ip_socket.rbs +31 -9
  149. data/stdlib/socket/0/socket.rbs +586 -38
  150. data/stdlib/socket/0/tcp_server.rbs +22 -2
  151. data/stdlib/socket/0/tcp_socket.rbs +12 -1
  152. data/stdlib/socket/0/udp_socket.rbs +25 -2
  153. data/stdlib/socket/0/unix_server.rbs +22 -2
  154. data/stdlib/socket/0/unix_socket.rbs +45 -5
  155. data/stdlib/strscan/0/string_scanner.rbs +210 -9
  156. data/stdlib/tempfile/0/tempfile.rbs +58 -10
  157. data/stdlib/time/0/time.rbs +208 -116
  158. data/stdlib/timeout/0/timeout.rbs +10 -0
  159. data/stdlib/tmpdir/0/tmpdir.rbs +13 -4
  160. data/stdlib/tsort/0/cyclic.rbs +1 -0
  161. data/stdlib/tsort/0/interfaces.rbs +1 -0
  162. data/stdlib/tsort/0/tsort.rbs +42 -0
  163. data/stdlib/uri/0/common.rbs +57 -8
  164. data/stdlib/uri/0/file.rbs +55 -109
  165. data/stdlib/uri/0/ftp.rbs +6 -3
  166. data/stdlib/uri/0/generic.rbs +556 -327
  167. data/stdlib/uri/0/http.rbs +26 -115
  168. data/stdlib/uri/0/https.rbs +8 -102
  169. data/stdlib/uri/0/ldap.rbs +143 -137
  170. data/stdlib/uri/0/ldaps.rbs +8 -102
  171. data/stdlib/uri/0/mailto.rbs +3 -0
  172. data/stdlib/uri/0/rfc2396_parser.rbs +66 -26
  173. data/stdlib/uri/0/ws.rbs +6 -3
  174. data/stdlib/uri/0/wss.rbs +5 -3
  175. data/stdlib/yaml/0/dbm.rbs +151 -87
  176. data/stdlib/yaml/0/store.rbs +6 -0
  177. data/stdlib/zlib/0/zlib.rbs +90 -31
  178. metadata +17 -5
  179. data/lib/rbs/location.rb +0 -221
data/core/kernel.rbs CHANGED
@@ -1,133 +1,683 @@
1
- # The [Kernel](Kernel) module is included by class
2
- # [Object](https://ruby-doc.org/core-2.6.3/Object.html), so its methods
3
- # are available in every Ruby object.
4
- #
5
- # The [Kernel](Kernel) instance methods are documented
6
- # in class [Object](https://ruby-doc.org/core-2.6.3/Object.html) while the
7
- # module methods are documented here. These methods are called without a
8
- # receiver and thus can be called in functional form:
9
- #
10
- # ```ruby
11
- # sprintf "%.1f", 1.234 #=> "1.2"
12
- # ```
1
+ # <!-- rdoc-file=object.c -->
2
+ # The Kernel module is included by class Object, so its methods are available in
3
+ # every Ruby object.
4
+ #
5
+ # The Kernel instance methods are documented in class Object while the module
6
+ # methods are documented here. These methods are called without a receiver and
7
+ # thus can be called in functional form:
8
+ #
9
+ # sprintf "%.1f", 1.234 #=> "1.2"
10
+ #
11
+ # ## What's Here
12
+ #
13
+ # Module Kernel provides methods that are useful for:
14
+ #
15
+ # * [Converting](#module-Kernel-label-Converting)
16
+ # * [Querying](#module-Kernel-label-Querying)
17
+ # * [Exiting](#module-Kernel-label-Exiting)
18
+ # * [Exceptions](#module-Kernel-label-Exceptions)
19
+ # * [IO](#module-Kernel-label-IO)
20
+ # * [Procs](#module-Kernel-label-Procs)
21
+ # * [Tracing](#module-Kernel-label-Tracing)
22
+ # * [Subprocesses](#module-Kernel-label-Subprocesses)
23
+ # * [Loading](#module-Kernel-label-Loading)
24
+ # * [Yielding](#module-Kernel-label-Yielding)
25
+ # * [Random Values](#module-Kernel-label-Random+Values)
26
+ # * [Other](#module-Kernel-label-Other)
27
+ #
28
+ #
29
+ # ### Converting
30
+ #
31
+ # [#Array](#method-i-Array)
32
+ # : Returns an Array based on the given argument.
33
+ #
34
+ # [#Complex](#method-i-Complex)
35
+ # : Returns a Complex based on the given arguments.
36
+ #
37
+ # [#Float](#method-i-Float)
38
+ # : Returns a Float based on the given arguments.
39
+ #
40
+ # [#Hash](#method-i-Hash)
41
+ # : Returns a Hash based on the given argument.
42
+ #
43
+ # [#Integer](#method-i-Integer)
44
+ # : Returns an Integer based on the given arguments.
45
+ #
46
+ # [#Rational](#method-i-Rational)
47
+ # : Returns a Rational based on the given arguments.
48
+ #
49
+ # [#String](#method-i-String)
50
+ # : Returns a String based on the given argument.
51
+ #
52
+ #
53
+ #
54
+ # ### Querying
55
+ #
56
+ # [#__callee__](#method-i-__callee__)
57
+ # : Returns the called name of the current method as a symbol.
58
+ #
59
+ # [#__dir__](#method-i-__dir__)
60
+ # : Returns the path to the directory from which the current method is
61
+ # called.
62
+ #
63
+ # [#__method__](#method-i-__method__)
64
+ # : Returns the name of the current method as a symbol.
65
+ #
66
+ # #autoload?
67
+ # : Returns the file to be loaded when the given module is referenced.
68
+ #
69
+ # #binding
70
+ # : Returns a Binding for the context at the point of call.
71
+ #
72
+ # #block_given?
73
+ # : Returns `true` if a block was passed to the calling method.
74
+ #
75
+ # #caller
76
+ # : Returns the current execution stack as an array of strings.
77
+ #
78
+ # #caller_locations
79
+ # : Returns the current execution stack as an array of
80
+ # Thread::Backtrace::Location objects.
81
+ #
82
+ # #class
83
+ # : Returns the class of `self`.
84
+ #
85
+ # #frozen?
86
+ # : Returns whether `self` is frozen.
87
+ #
88
+ # #global_variables
89
+ # : Returns an array of global variables as symbols.
90
+ #
91
+ # #local_variables
92
+ # : Returns an array of local variables as symbols.
93
+ #
94
+ # #test
95
+ # : Performs specified tests on the given single file or pair of files.
96
+ #
97
+ #
98
+ #
99
+ # ### Exiting
100
+ #
101
+ # #abort
102
+ # : Exits the current process after printing the given arguments.
103
+ #
104
+ # #at_exit
105
+ # : Executes the given block when the process exits.
106
+ #
107
+ # #exit
108
+ # : Exits the current process after calling any registered `at_exit`
109
+ # handlers.
110
+ #
111
+ # #exit!
112
+ # : Exits the current process without calling any registered `at_exit`
113
+ # handlers.
114
+ #
115
+ #
116
+ #
117
+ # ### Exceptions
118
+ #
119
+ # #catch
120
+ # : Executes the given block, possibly catching a thrown object.
121
+ #
122
+ # #raise (aliased as #fail)
123
+ # : Raises an exception based on the given arguments.
124
+ #
125
+ # #throw
126
+ # : Returns from the active catch block waiting for the given tag.
127
+ #
128
+ #
129
+ #
130
+ # ### IO
131
+ #
132
+ # #gets
133
+ # : Returns and assigns to `$_` the next line from the current input.
134
+ #
135
+ # #open
136
+ # : Creates an IO object connected to the given stream, file, or
137
+ # subprocess.
138
+ #
139
+ # #p
140
+ # : Prints the given objects' inspect output to the standard output.
141
+ #
142
+ # #pp
143
+ # : Prints the given objects in pretty form.
144
+ #
145
+ # #print
146
+ # : Prints the given objects to standard output without a newline.
147
+ #
148
+ # #printf
149
+ # : Prints the string resulting from applying the given format string to
150
+ # any additional arguments.
151
+ #
152
+ # #putc
153
+ # : Equivalent to <tt.$stdout.putc(object)</tt> for the given object.
154
+ #
155
+ # #puts
156
+ # : Equivalent to `$stdout.puts(*objects)` for the given objects.
157
+ #
158
+ # #readline
159
+ # : Similar to #gets, but raises an exception at the end of file.
160
+ #
161
+ # #readlines
162
+ # : Returns an array of the remaining lines from the current input.
163
+ #
164
+ # #select
165
+ # : Same as IO.select.
166
+ #
167
+ #
168
+ #
169
+ # ### Procs
170
+ #
171
+ # #lambda
172
+ # : Returns a lambda proc for the given block.
173
+ #
174
+ # #proc
175
+ # : Returns a new Proc; equivalent to Proc.new.
176
+ #
177
+ #
178
+ #
179
+ # ### Tracing
180
+ #
181
+ # #set_trace_func
182
+ # : Sets the given proc as the handler for tracing, or disables tracing if
183
+ # given `nil`.
184
+ #
185
+ # #trace_var
186
+ # : Starts tracing assignments to the given global variable.
187
+ #
188
+ # #untrace_var
189
+ # : Disables tracing of assignments to the given global variable.
190
+ #
191
+ #
192
+ #
193
+ # ### Subprocesses
194
+ #
195
+ # #`cmd`
196
+ # : Returns the standard output of running `cmd` in a subshell.
197
+ #
198
+ # #exec
199
+ # : Replaces current process with a new process.
200
+ #
201
+ # #fork
202
+ # : Forks the current process into two processes.
203
+ #
204
+ # #spawn
205
+ # : Executes the given command and returns its pid without waiting for
206
+ # completion.
207
+ #
208
+ # #system
209
+ # : Executes the given command in a subshell.
210
+ #
211
+ #
212
+ #
213
+ # ### Loading
214
+ #
215
+ # #autoload
216
+ # : Registers the given file to be loaded when the given constant is first
217
+ # referenced.
218
+ #
219
+ # #load
220
+ # : Loads the given Ruby file.
221
+ #
222
+ # #require
223
+ # : Loads the given Ruby file unless it has already been loaded.
224
+ #
225
+ # #require_relative
226
+ # : Loads the Ruby file path relative to the calling file, unless it has
227
+ # already been loaded.
228
+ #
229
+ #
230
+ #
231
+ # ### Yielding
232
+ #
233
+ # #tap
234
+ # : Yields `self` to the given block; returns `self`.
235
+ #
236
+ # #then (aliased as #yield_self)
237
+ # : Yields `self` to the block and returns the result of the block.
238
+ #
239
+ #
240
+ #
241
+ # ### Random Values
242
+ #
243
+ # #rand
244
+ # : Returns a pseudo-random floating point number strictly between 0.0 and
245
+ # 1.0.
246
+ #
247
+ # #srand
248
+ # : Seeds the pseudo-random number generator with the given number.
249
+ #
250
+ #
251
+ #
252
+ # ### Other
253
+ #
254
+ # #eval
255
+ # : Evaluates the given string as Ruby code.
256
+ #
257
+ # #loop
258
+ # : Repeatedly executes the given block.
259
+ #
260
+ # #sleep
261
+ # : Suspends the current thread for the given number of seconds.
262
+ #
263
+ # #sprintf (aliased as #format)
264
+ # : Returns the string resulting from applying the given format string to
265
+ # any additional arguments.
266
+ #
267
+ # #syscall
268
+ # : Runs an operating system call.
269
+ #
270
+ # #trap
271
+ # : Specifies the handling of system signals.
272
+ #
273
+ # #warn
274
+ # : Issue a warning based on the given messages and options.
275
+ #
276
+ %a{annotate:rdoc:source:from=object.c}
13
277
  module Kernel : BasicObject
14
278
  private
15
279
 
280
+ # <!--
281
+ # rdoc-file=vm_backtrace.c
282
+ # - caller(start=1, length=nil) -> array or nil
283
+ # - caller(range) -> array or nil
284
+ # -->
285
+ # Returns the current execution stack---an array containing strings in the form
286
+ # `file:line` or `file:line: in `method'`.
287
+ #
288
+ # The optional *start* parameter determines the number of initial stack entries
289
+ # to omit from the top of the stack.
290
+ #
291
+ # A second optional `length` parameter can be used to limit how many entries are
292
+ # returned from the stack.
293
+ #
294
+ # Returns `nil` if *start* is greater than the size of current execution stack.
295
+ #
296
+ # Optionally you can pass a range, which will return an array containing the
297
+ # entries within the specified range.
298
+ #
299
+ # def a(skip)
300
+ # caller(skip)
301
+ # end
302
+ # def b(skip)
303
+ # a(skip)
304
+ # end
305
+ # def c(skip)
306
+ # b(skip)
307
+ # end
308
+ # c(0) #=> ["prog:2:in `a'", "prog:5:in `b'", "prog:8:in `c'", "prog:10:in `<main>'"]
309
+ # c(1) #=> ["prog:5:in `b'", "prog:8:in `c'", "prog:11:in `<main>'"]
310
+ # c(2) #=> ["prog:8:in `c'", "prog:12:in `<main>'"]
311
+ # c(3) #=> ["prog:13:in `<main>'"]
312
+ # c(4) #=> []
313
+ # c(5) #=> nil
314
+ #
16
315
  def self?.caller: (Integer start_or_range, ?Integer length) -> ::Array[String]?
17
- | (::Range[Integer] start_or_range) -> ::Array[String]?
18
- | () -> ::Array[String]
316
+ | (::Range[Integer] start_or_range) -> ::Array[String]?
317
+ | () -> ::Array[String]
19
318
 
319
+ # <!--
320
+ # rdoc-file=vm_backtrace.c
321
+ # - caller_locations(start=1, length=nil) -> array or nil
322
+ # - caller_locations(range) -> array or nil
323
+ # -->
324
+ # Returns the current execution stack---an array containing backtrace location
325
+ # objects.
326
+ #
327
+ # See Thread::Backtrace::Location for more information.
328
+ #
329
+ # The optional *start* parameter determines the number of initial stack entries
330
+ # to omit from the top of the stack.
331
+ #
332
+ # A second optional `length` parameter can be used to limit how many entries are
333
+ # returned from the stack.
334
+ #
335
+ # Returns `nil` if *start* is greater than the size of current execution stack.
336
+ #
337
+ # Optionally you can pass a range, which will return an array containing the
338
+ # entries within the specified range.
339
+ #
20
340
  def self?.caller_locations: (?Integer start_or_range, ?Integer length) -> ::Array[Thread::Backtrace::Location]?
21
- | (?::Range[Integer] start_or_range) -> ::Array[Thread::Backtrace::Location]?
22
-
23
- def self?.catch: [T] (T tag) { (T tag) -> untyped } -> untyped
24
- | () { (Object tag) -> untyped } -> untyped
341
+ | (?::Range[Integer] start_or_range) -> ::Array[Thread::Backtrace::Location]?
25
342
 
26
- # In a perfect world this should be:
343
+ # <!--
344
+ # rdoc-file=vm_eval.c
345
+ # - catch([tag]) {|tag| block } -> obj
346
+ # -->
347
+ # `catch` executes its block. If `throw` is not called, the block executes
348
+ # normally, and `catch` returns the value of the last expression evaluated.
349
+ #
350
+ # catch(1) { 123 } # => 123
351
+ #
352
+ # If `throw(tag2, val)` is called, Ruby searches up its stack for a `catch`
353
+ # block whose `tag` has the same `object_id` as *tag2*. When found, the block
354
+ # stops executing and returns *val* (or `nil` if no second argument was given to
355
+ # `throw`).
356
+ #
357
+ # catch(1) { throw(1, 456) } # => 456
358
+ # catch(1) { throw(1) } # => nil
359
+ #
360
+ # When `tag` is passed as the first argument, `catch` yields it as the parameter
361
+ # of the block.
362
+ #
363
+ # catch(1) {|x| x + 2 } # => 3
364
+ #
365
+ # When no `tag` is given, `catch` yields a new unique object (as from
366
+ # `Object.new`) as the block parameter. This object can then be used as the
367
+ # argument to `throw`, and will match the correct `catch` block.
368
+ #
369
+ # catch do |obj_A|
370
+ # catch do |obj_B|
371
+ # throw(obj_B, 123)
372
+ # puts "This puts is not reached"
373
+ # end
374
+ #
375
+ # puts "This puts is displayed"
376
+ # 456
377
+ # end
378
+ #
379
+ # # => 456
27
380
  #
28
- # returns(T.class_of(T.self_type))
381
+ # catch do |obj_A|
382
+ # catch do |obj_B|
383
+ # throw(obj_A, 123)
384
+ # puts "This puts is still not reached"
385
+ # end
29
386
  #
30
- # but that doesn't work (yet). Even making it:
387
+ # puts "Now this puts is also not reached"
388
+ # 456
389
+ # end
31
390
  #
32
- # returns(Class)
391
+ # # => 123
33
392
  #
34
- # is very surprising since users expect their methods to be present.
35
- # So we settle for untyped.
36
- def `class`: () -> untyped
393
+ def self?.catch: [T] (T tag) { (T tag) -> untyped } -> untyped
394
+ | () { (Object tag) -> untyped } -> untyped
37
395
 
38
- def define_singleton_method: (Symbol | String symbol, ?Proc | Method | UnboundMethod method) -> Symbol
39
- | (Symbol | String symbol) { () -> untyped } -> Symbol
396
+ # <!--
397
+ # rdoc-file=kernel.rb
398
+ # - obj.class -> class
399
+ # -->
400
+ # Returns the class of *obj*. This method must always be called with an explicit
401
+ # receiver, as #class is also a reserved word in Ruby.
402
+ #
403
+ # 1.class #=> Integer
404
+ # self.class #=> Object
405
+ #
406
+ def class: () -> untyped
40
407
 
408
+ # <!--
409
+ # rdoc-file=vm_eval.c
410
+ # - eval(string [, binding [, filename [,lineno]]]) -> obj
411
+ # -->
412
+ # Evaluates the Ruby expression(s) in *string*. If *binding* is given, which
413
+ # must be a Binding object, the evaluation is performed in its context. If the
414
+ # optional *filename* and *lineno* parameters are present, they will be used
415
+ # when reporting syntax errors.
416
+ #
417
+ # def get_binding(str)
418
+ # return binding
419
+ # end
420
+ # str = "hello"
421
+ # eval "str + ' Fred'" #=> "hello Fred"
422
+ # eval "str + ' Fred'", get_binding("bye") #=> "bye Fred"
423
+ #
41
424
  def self?.eval: (String arg0, ?Binding arg1, ?String filename, ?Integer lineno) -> untyped
42
425
 
43
- # Returns `true` if `yield` would execute a block in the current context.
44
- #
45
- # ```ruby
46
- # def try
47
- # if block_given?
48
- # yield
49
- # else
50
- # "no block"
51
- # end
52
- # end
53
- # try #=> "no block"
54
- # try { "hello" } #=> "hello"
55
- # try do "hello" end #=> "hello"
56
- # ```
426
+ # <!--
427
+ # rdoc-file=vm_eval.c
428
+ # - block_given? -> true or false
429
+ # -->
430
+ # Returns `true` if `yield` would execute a block in the current context. The
431
+ # `iterator?` form is mildly deprecated.
432
+ #
433
+ # def try
434
+ # if block_given?
435
+ # yield
436
+ # else
437
+ # "no block"
438
+ # end
439
+ # end
440
+ # try #=> "no block"
441
+ # try { "hello" } #=> "hello"
442
+ # try do "hello" end #=> "hello"
443
+ #
57
444
  def self?.block_given?: () -> bool
58
445
 
446
+ # <!--
447
+ # rdoc-file=vm_eval.c
448
+ # - local_variables -> array
449
+ # -->
59
450
  # Returns the names of the current local variables.
60
451
  #
61
- # ```ruby
62
- # fred = 1
63
- # for i in 1..10
64
- # # ...
65
- # end
66
- # local_variables #=> [:fred, :i]
67
- # ```
452
+ # fred = 1
453
+ # for i in 1..10
454
+ # # ...
455
+ # end
456
+ # local_variables #=> [:fred, :i]
457
+ #
68
458
  def self?.local_variables: () -> ::Array[Symbol]
69
459
 
460
+ # <!--
461
+ # rdoc-file=random.c
462
+ # - srand(number = Random.new_seed) -> old_seed
463
+ # -->
464
+ # Seeds the system pseudo-random number generator, with `number`. The previous
465
+ # seed value is returned.
466
+ #
467
+ # If `number` is omitted, seeds the generator using a source of entropy provided
468
+ # by the operating system, if available (/dev/urandom on Unix systems or the RSA
469
+ # cryptographic provider on Windows), which is then combined with the time, the
470
+ # process id, and a sequence number.
471
+ #
472
+ # srand may be used to ensure repeatable sequences of pseudo-random numbers
473
+ # between different runs of the program. By setting the seed to a known value,
474
+ # programs can be made deterministic during testing.
475
+ #
476
+ # srand 1234 # => 268519324636777531569100071560086917274
477
+ # [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
478
+ # [ rand(10), rand(1000) ] # => [4, 664]
479
+ # srand 1234 # => 1234
480
+ # [ rand, rand ] # => [0.1915194503788923, 0.6221087710398319]
481
+ #
70
482
  def self?.srand: (?Numeric number) -> Numeric
71
483
 
484
+ # <!--
485
+ # rdoc-file=process.c
486
+ # - Kernel.fork [{ block }] -> integer or nil
487
+ # - Process.fork [{ block }] -> integer or nil
488
+ # -->
72
489
  # Creates a subprocess. If a block is specified, that block is run in the
73
- # subprocess, and the subprocess terminates with a status of zero.
74
- # Otherwise, the `fork` call returns twice, once in the parent, returning
75
- # the process ID of the child, and once in the child, returning *nil* .
76
- # The child process can exit using `Kernel.exit!` to avoid running any
77
- # `at_exit` functions. The parent process should use `Process.wait` to
78
- # collect the termination statuses of its children or use `Process.detach`
79
- # to register disinterest in their status; otherwise, the operating system
80
- # may accumulate zombie processes.
81
- #
82
- # The thread calling fork is the only thread in the created child process.
83
- # fork doesn’t copy other threads.
84
- #
85
- # If fork is not usable, Process.respond\_to?(:fork) returns false.
86
- #
87
- # Note that fork(2) is not available on some platforms like Windows and
88
- # NetBSD 4. Therefore you should use spawn() instead of fork().
490
+ # subprocess, and the subprocess terminates with a status of zero. Otherwise,
491
+ # the `fork` call returns twice, once in the parent, returning the process ID of
492
+ # the child, and once in the child, returning *nil*. The child process can exit
493
+ # using Kernel.exit! to avoid running any `at_exit` functions. The parent
494
+ # process should use Process.wait to collect the termination statuses of its
495
+ # children or use Process.detach to register disinterest in their status;
496
+ # otherwise, the operating system may accumulate zombie processes.
497
+ #
498
+ # The thread calling fork is the only thread in the created child process. fork
499
+ # doesn't copy other threads.
500
+ #
501
+ # If fork is not usable, Process.respond_to?(:fork) returns false.
502
+ #
503
+ # Note that fork(2) is not available on some platforms like Windows and NetBSD
504
+ # 4. Therefore you should use spawn() instead of fork().
505
+ #
89
506
  def self?.fork: () -> Integer?
90
- | () { () -> untyped } -> Integer?
507
+ | () { () -> untyped } -> Integer?
91
508
 
92
509
  def initialize_copy: (self object) -> self
93
510
 
94
- # Returns `arg` as an [Array](https://ruby-doc.org/core-2.6.3/Array.html)
95
- # .
96
- #
97
- # First tries to call `to_ary` on `arg`, then `to_a` . If `arg` does not
98
- # respond to `to_ary` or `to_a`, returns an
99
- # [Array](https://ruby-doc.org/core-2.6.3/Array.html) of length 1
100
- # containing `arg` .
101
- #
102
- # If `to_ary` or `to_a` returns something other than an
103
- # [Array](https://ruby-doc.org/core-2.6.3/Array.html), raises a
104
- # `TypeError` .
105
- #
106
- # ```ruby
107
- # Array(["a", "b"]) #=> ["a", "b"]
108
- # Array(1..5) #=> [1, 2, 3, 4, 5]
109
- # Array(key: :value) #=> [[:key, :value]]
110
- # Array(nil) #=> []
111
- # Array(1) #=> [1]
112
- # ```
511
+ # <!--
512
+ # rdoc-file=object.c
513
+ # - Array(arg) -> array
514
+ # -->
515
+ # Returns `arg` as an Array.
516
+ #
517
+ # First tries to call `to_ary` on `arg`, then `to_a`. If `arg` does not respond
518
+ # to `to_ary` or `to_a`, returns an Array of length 1 containing `arg`.
519
+ #
520
+ # If `to_ary` or `to_a` returns something other than an Array, raises a
521
+ # TypeError.
522
+ #
523
+ # Array(["a", "b"]) #=> ["a", "b"]
524
+ # Array(1..5) #=> [1, 2, 3, 4, 5]
525
+ # Array(key: :value) #=> [[:key, :value]]
526
+ # Array(nil) #=> []
527
+ # Array(1) #=> [1]
528
+ #
113
529
  def self?.Array: (NilClass x) -> [ ]
114
- | [T] (::Array[T] x) -> ::Array[T]
115
- | [T] (::Range[T] x) -> ::Array[T]
116
- | [T] (_Each[T] x) -> ::Array[T]
117
- | [K, V] (::Hash[K, V] x) -> ::Array[[K, V]]
118
- | [T] (T x) -> ::Array[T]
530
+ | [T] (::Array[T] x) -> ::Array[T]
531
+ | [T] (::Range[T] x) -> ::Array[T]
532
+ | [T] (_Each[T] x) -> ::Array[T]
533
+ | [K, V] (::Hash[K, V] x) -> ::Array[[ K, V ]]
534
+ | [T] (T x) -> ::Array[T]
119
535
 
536
+ # <!--
537
+ # rdoc-file=complex.c
538
+ # - Complex(x[, y], exception: true) -> numeric or nil
539
+ # -->
540
+ # Returns x+i*y;
541
+ #
542
+ # Complex(1, 2) #=> (1+2i)
543
+ # Complex('1+2i') #=> (1+2i)
544
+ # Complex(nil) #=> TypeError
545
+ # Complex(1, nil) #=> TypeError
546
+ #
547
+ # Complex(1, nil, exception: false) #=> nil
548
+ # Complex('1+2', exception: false) #=> nil
549
+ #
550
+ # Syntax of string form:
551
+ #
552
+ # string form = extra spaces , complex , extra spaces ;
553
+ # complex = real part | [ sign ] , imaginary part
554
+ # | real part , sign , imaginary part
555
+ # | rational , "@" , rational ;
556
+ # real part = rational ;
557
+ # imaginary part = imaginary unit | unsigned rational , imaginary unit ;
558
+ # rational = [ sign ] , unsigned rational ;
559
+ # unsigned rational = numerator | numerator , "/" , denominator ;
560
+ # numerator = integer part | fractional part | integer part , fractional part ;
561
+ # denominator = digits ;
562
+ # integer part = digits ;
563
+ # fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
564
+ # imaginary unit = "i" | "I" | "j" | "J" ;
565
+ # sign = "-" | "+" ;
566
+ # digits = digit , { digit | "_" , digit };
567
+ # digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
568
+ # extra spaces = ? \s* ? ;
569
+ #
570
+ # See String#to_c.
571
+ #
120
572
  def self?.Complex: (Numeric | String x, ?Numeric | String y, ?exception: bool exception) -> Complex
121
573
 
574
+ # <!--
575
+ # rdoc-file=kernel.rb
576
+ # - Float(arg, exception: true) -> float or nil
577
+ # -->
578
+ # Returns *arg* converted to a float. Numeric types are converted directly, and
579
+ # with exception to String and `nil` the rest are converted using *arg*`.to_f`.
580
+ # Converting a String with invalid characters will result in a ArgumentError.
581
+ # Converting `nil` generates a TypeError. Exceptions can be suppressed by
582
+ # passing `exception: false`.
583
+ #
584
+ # Float(1) #=> 1.0
585
+ # Float("123.456") #=> 123.456
586
+ # Float("123.0_badstring") #=> ArgumentError: invalid value for Float(): "123.0_badstring"
587
+ # Float(nil) #=> TypeError: can't convert nil into Float
588
+ # Float("123.0_badstring", exception: false) #=> nil
589
+ #
122
590
  def self?.Float: (Numeric | String x, ?exception: bool exception) -> Float
123
591
 
592
+ # <!--
593
+ # rdoc-file=object.c
594
+ # - Hash(arg) -> hash
595
+ # -->
596
+ # Converts *arg* to a Hash by calling *arg*`.to_hash`. Returns an empty Hash
597
+ # when *arg* is `nil` or `[]`.
598
+ #
599
+ # Hash([]) #=> {}
600
+ # Hash(nil) #=> {}
601
+ # Hash(key: :value) #=> {:key => :value}
602
+ # Hash([1, 2, 3]) #=> TypeError
603
+ #
124
604
  def self?.Hash: [K, V] (Object x) -> ::Hash[K, V]
125
605
 
606
+ # <!--
607
+ # rdoc-file=object.c
608
+ # - Integer(arg, base=0, exception: true) -> integer or nil
609
+ # -->
610
+ # Converts *arg* to an Integer. Numeric types are converted directly (with
611
+ # floating point numbers being truncated). *base* (0, or between 2 and 36) is a
612
+ # base for integer string representation. If *arg* is a String, when *base* is
613
+ # omitted or equals zero, radix indicators (`0`, `0b`, and `0x`) are honored. In
614
+ # any case, strings should consist only of one or more digits, except for that a
615
+ # sign, one underscore between two digits, and leading/trailing spaces are
616
+ # optional. This behavior is different from that of String#to_i. Non string
617
+ # values will be converted by first trying `to_int`, then `to_i`.
618
+ #
619
+ # Passing `nil` raises a TypeError, while passing a String that does not conform
620
+ # with numeric representation raises an ArgumentError. This behavior can be
621
+ # altered by passing `exception: false`, in this case a not convertible value
622
+ # will return `nil`.
623
+ #
624
+ # Integer(123.999) #=> 123
625
+ # Integer("0x1a") #=> 26
626
+ # Integer(Time.new) #=> 1204973019
627
+ # Integer("0930", 10) #=> 930
628
+ # Integer("111", 2) #=> 7
629
+ # Integer(" +1_0 ") #=> 10
630
+ # Integer(nil) #=> TypeError: can't convert nil into Integer
631
+ # Integer("x") #=> ArgumentError: invalid value for Integer(): "x"
632
+ #
633
+ # Integer("x", exception: false) #=> nil
634
+ #
126
635
  def self?.Integer: (Numeric | String arg, ?exception: bool exception) -> Integer
127
- | (String arg, ?Integer base, ?exception: bool exception) -> Integer
636
+ | (String arg, ?Integer base, ?exception: bool exception) -> Integer
128
637
 
638
+ # <!--
639
+ # rdoc-file=rational.c
640
+ # - Rational(x, y, exception: true) -> rational or nil
641
+ # - Rational(arg, exception: true) -> rational or nil
642
+ # -->
643
+ # Returns `x/y` or `arg` as a Rational.
644
+ #
645
+ # Rational(2, 3) #=> (2/3)
646
+ # Rational(5) #=> (5/1)
647
+ # Rational(0.5) #=> (1/2)
648
+ # Rational(0.3) #=> (5404319552844595/18014398509481984)
649
+ #
650
+ # Rational("2/3") #=> (2/3)
651
+ # Rational("0.3") #=> (3/10)
652
+ #
653
+ # Rational("10 cents") #=> ArgumentError
654
+ # Rational(nil) #=> TypeError
655
+ # Rational(1, nil) #=> TypeError
656
+ #
657
+ # Rational("10 cents", exception: false) #=> nil
658
+ #
659
+ # Syntax of the string form:
660
+ #
661
+ # string form = extra spaces , rational , extra spaces ;
662
+ # rational = [ sign ] , unsigned rational ;
663
+ # unsigned rational = numerator | numerator , "/" , denominator ;
664
+ # numerator = integer part | fractional part | integer part , fractional part ;
665
+ # denominator = digits ;
666
+ # integer part = digits ;
667
+ # fractional part = "." , digits , [ ( "e" | "E" ) , [ sign ] , digits ] ;
668
+ # sign = "-" | "+" ;
669
+ # digits = digit , { digit | "_" , digit } ;
670
+ # digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
671
+ # extra spaces = ? \s* ? ;
672
+ #
673
+ # See also String#to_r.
674
+ #
129
675
  def self?.Rational: (Numeric | String | Object x, ?Numeric | String y, ?exception: bool exception) -> Rational
130
676
 
677
+ # <!--
678
+ # rdoc-file=object.c
679
+ # - String(arg) -> string
680
+ # -->
131
681
  # Returns *arg* as a String.
132
682
  #
133
683
  # First tries to call its `to_str` method, then its `to_s` method.
@@ -138,61 +688,139 @@ module Kernel : BasicObject
138
688
  #
139
689
  def self?.String: (_ToStr | _ToS x) -> String
140
690
 
141
- # Returns the called name of the current method as a
142
- # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html). If called
143
- # outside of a method, it returns `nil` .
691
+ # <!--
692
+ # rdoc-file=eval.c
693
+ # - __callee__ -> symbol
694
+ # -->
695
+ # Returns the called name of the current method as a Symbol. If called outside
696
+ # of a method, it returns `nil`.
697
+ #
144
698
  def self?.__callee__: () -> Symbol?
145
699
 
146
- # Returns the canonicalized absolute path of the directory of the file
147
- # from which this method is called. It means symlinks in the path is
148
- # resolved. If `__FILE__` is `nil`, it returns `nil` . The return value
149
- # equals to `File.dirname(File.realpath(__FILE__))` .
700
+ # <!--
701
+ # rdoc-file=eval.c
702
+ # - __dir__ -> string
703
+ # -->
704
+ # Returns the canonicalized absolute path of the directory of the file from
705
+ # which this method is called. It means symlinks in the path is resolved. If
706
+ # `__FILE__` is `nil`, it returns `nil`. The return value equals to
707
+ # `File.dirname(File.realpath(__FILE__))`.
708
+ #
150
709
  def self?.__dir__: () -> String?
151
710
 
152
- # Returns the name at the definition of the current method as a
153
- # [Symbol](https://ruby-doc.org/core-2.6.3/Symbol.html). If called
154
- # outside of a method, it returns `nil` .
711
+ # <!--
712
+ # rdoc-file=eval.c
713
+ # - __method__ -> symbol
714
+ # -->
715
+ # Returns the name at the definition of the current method as a Symbol. If
716
+ # called outside of a method, it returns `nil`.
717
+ #
155
718
  def self?.__method__: () -> Symbol?
156
719
 
720
+ # <!--
721
+ # rdoc-file=io.c
722
+ # - `cmd` -> string
723
+ # -->
724
+ # Returns the standard output of running *cmd* in a subshell. The built-in
725
+ # syntax `%x{...}` uses this method. Sets `$?` to the process status.
726
+ #
727
+ # `date` #=> "Wed Apr 9 08:56:30 CDT 2003\n"
728
+ # `ls testdir`.split[1] #=> "main.rb"
729
+ # `echo oops && exit 99` #=> "oops\n"
730
+ # $?.exitstatus #=> 99
731
+ #
157
732
  def self?.`: (String arg0) -> String
158
733
 
734
+ # <!--
735
+ # rdoc-file=process.c
736
+ # - abort
737
+ # - Kernel::abort([msg])
738
+ # - Process.abort([msg])
739
+ # -->
740
+ # Terminate execution immediately, effectively by calling `Kernel.exit(false)`.
741
+ # If *msg* is given, it is written to STDERR prior to terminating.
742
+ #
159
743
  def self?.abort: (?String msg) -> bot
160
744
 
745
+ # <!--
746
+ # rdoc-file=eval_jump.c
747
+ # - at_exit { block } -> proc
748
+ # -->
749
+ # Converts *block* to a `Proc` object (and therefore binds it at the point of
750
+ # call) and registers it for execution when the program exits. If multiple
751
+ # handlers are registered, they are executed in reverse order of registration.
752
+ #
753
+ # def do_at_exit(str1)
754
+ # at_exit { print str1 }
755
+ # end
756
+ # at_exit { puts "cruel world" }
757
+ # do_at_exit("goodbye ")
758
+ # exit
759
+ #
760
+ # *produces:*
761
+ #
762
+ # goodbye cruel world
763
+ #
161
764
  def self?.at_exit: () { () -> untyped } -> Proc
162
765
 
766
+ # <!--
767
+ # rdoc-file=load.c
768
+ # - autoload(module, filename) -> nil
769
+ # -->
770
+ # Registers *filename* to be loaded (using Kernel::require) the first time that
771
+ # *module* (which may be a String or a symbol) is accessed.
772
+ #
773
+ # autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
774
+ #
163
775
  def self?.autoload: (String | Symbol _module, String filename) -> NilClass
164
776
 
777
+ # <!--
778
+ # rdoc-file=load.c
779
+ # - autoload?(name, inherit=true) -> String or nil
780
+ # -->
781
+ # Returns *filename* to be loaded if *name* is registered as `autoload`.
782
+ #
783
+ # autoload(:B, "b")
784
+ # autoload?(:B) #=> "b"
785
+ #
165
786
  def self?.autoload?: (Symbol | String name) -> String?
166
787
 
167
- # Returns a `Binding` object, describing the variable and method bindings
168
- # at the point of call. This object can be used when calling `eval` to
169
- # execute the evaluated command in this environment. See also the
170
- # description of class `Binding` .
171
- #
172
- # ```ruby
173
- # def get_binding(param)
174
- # binding
175
- # end
176
- # b = get_binding("hello")
177
- # eval("param", b) #=> "hello"
178
- # ```
788
+ # <!--
789
+ # rdoc-file=proc.c
790
+ # - binding -> a_binding
791
+ # -->
792
+ # Returns a `Binding` object, describing the variable and method bindings at the
793
+ # point of call. This object can be used when calling `eval` to execute the
794
+ # evaluated command in this environment. See also the description of class
795
+ # `Binding`.
796
+ #
797
+ # def get_binding(param)
798
+ # binding
799
+ # end
800
+ # b = get_binding("hello")
801
+ # eval("param", b) #=> "hello"
802
+ #
179
803
  def self?.binding: () -> Binding
180
804
 
181
- # Initiates the termination of the Ruby script by raising the `SystemExit`
182
- # exception. This exception may be caught. The optional parameter is used
183
- # to return a status code to the invoking environment. `true` and `FALSE`
184
- # of *status* means success and failure respectively. The interpretation
185
- # of other integer values are system dependent.
186
- #
187
- # ```ruby
188
- # begin
189
- # exit
190
- # puts "never get here"
191
- # rescue SystemExit
192
- # puts "rescued a SystemExit exception"
193
- # end
194
- # puts "after begin block"
195
- # ```
805
+ # <!--
806
+ # rdoc-file=process.c
807
+ # - exit(status=true)
808
+ # - Kernel::exit(status=true)
809
+ # - Process::exit(status=true)
810
+ # -->
811
+ # Initiates the termination of the Ruby script by raising the SystemExit
812
+ # exception. This exception may be caught. The optional parameter is used to
813
+ # return a status code to the invoking environment. `true` and `FALSE` of
814
+ # *status* means success and failure respectively. The interpretation of other
815
+ # integer values are system dependent.
816
+ #
817
+ # begin
818
+ # exit
819
+ # puts "never get here"
820
+ # rescue SystemExit
821
+ # puts "rescued a SystemExit exception"
822
+ # end
823
+ # puts "after begin block"
196
824
  #
197
825
  # *produces:*
198
826
  #
@@ -200,318 +828,1689 @@ module Kernel : BasicObject
200
828
  # after begin block
201
829
  #
202
830
  # Just prior to termination, Ruby executes any `at_exit` functions (see
203
- # Kernel::at\_exit) and runs any object finalizers (see
204
- # [ObjectSpace.define\_finalizer](https://ruby-doc.org/core-2.6.3/ObjectSpace.html#method-c-define_finalizer)
205
- # ).
831
+ # Kernel::at_exit) and runs any object finalizers (see
832
+ # ObjectSpace::define_finalizer).
206
833
  #
207
- # ```ruby
208
- # at_exit { puts "at_exit function" }
209
- # ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
210
- # exit
211
- # ```
834
+ # at_exit { puts "at_exit function" }
835
+ # ObjectSpace.define_finalizer("string", proc { puts "in finalizer" })
836
+ # exit
212
837
  #
213
838
  # *produces:*
214
839
  #
215
840
  # at_exit function
216
841
  # in finalizer
842
+ #
217
843
  def self?.exit: () -> bot
218
- | (?Integer | TrueClass | FalseClass status) -> bot
844
+ | (?Integer | TrueClass | FalseClass status) -> bot
219
845
 
846
+ # <!--
847
+ # rdoc-file=process.c
848
+ # - Process.exit!(status=false)
849
+ # -->
850
+ # Exits the process immediately. No exit handlers are run. *status* is returned
851
+ # to the underlying system as the exit status.
852
+ #
853
+ # Process.exit!(true)
854
+ #
220
855
  def self?.exit!: (Integer | TrueClass | FalseClass status) -> bot
221
856
 
222
- # With no arguments, raises the exception in `$!` or raises a
223
- # `RuntimeError` if `$!` is `nil` . With a single `String` argument,
224
- # raises a `RuntimeError` with the string as a message. Otherwise, the
225
- # first parameter should be the name of an `Exception` class (or an object
226
- # that returns an `Exception` object when sent an `exception` message).
227
- # The optional second parameter sets the message associated with the
228
- # exception, and the third parameter is an array of callback information.
857
+ # <!-- rdoc-file=eval.c -->
858
+ # With no arguments, raises the exception in `$!` or raises a RuntimeError if
859
+ # `$!` is `nil`. With a single `String` argument, raises a `RuntimeError` with
860
+ # the string as a message. Otherwise, the first parameter should be an
861
+ # `Exception` class (or another object that returns an `Exception` object when
862
+ # sent an `exception` message). The optional second parameter sets the message
863
+ # associated with the exception (accessible via Exception#message), and the
864
+ # third parameter is an array of callback information (accessible via
865
+ # Exception#backtrace). The `cause` of the generated exception (accessible via
866
+ # Exception#cause) is automatically set to the "current" exception (`$!`), if
867
+ # any. An alternative value, either an `Exception` object or `nil`, can be
868
+ # specified via the `:cause` argument.
869
+ #
229
870
  # Exceptions are caught by the `rescue` clause of `begin...end` blocks.
230
871
  #
231
- # ```ruby
232
- # raise "Failed to create socket"
233
- # raise ArgumentError, "No parameters", caller
234
- # ```
872
+ # raise "Failed to create socket"
873
+ # raise ArgumentError, "No parameters", caller
235
874
  #
236
- # The `cause` of the generated exception is automatically set to the
237
- # “current” exception ( `$!` ) if any. An alternative value, either an
238
- # `Exception` object or `nil`, can be specified via the `:cause`
239
- # argument.
240
875
  def self?.fail: () -> bot
241
- | (String arg0) -> bot
242
- | (_Exception arg0, ?untyped arg1, ?::Array[String] arg2) -> bot
876
+ | (String arg0) -> bot
877
+ | (_Exception arg0, ?untyped arg1, ?::Array[String] arg2) -> bot
878
+
879
+ # <!--
880
+ # rdoc-file=eval.c
881
+ # - raise
882
+ # - raise(string, cause: $!)
883
+ # - raise(exception [, string [, array]], cause: $!)
884
+ # - fail
885
+ # - fail(string, cause: $!)
886
+ # - fail(exception [, string [, array]], cause: $!)
887
+ # -->
888
+ # With no arguments, raises the exception in `$!` or raises a RuntimeError if
889
+ # `$!` is `nil`. With a single `String` argument, raises a `RuntimeError` with
890
+ # the string as a message. Otherwise, the first parameter should be an
891
+ # `Exception` class (or another object that returns an `Exception` object when
892
+ # sent an `exception` message). The optional second parameter sets the message
893
+ # associated with the exception (accessible via Exception#message), and the
894
+ # third parameter is an array of callback information (accessible via
895
+ # Exception#backtrace). The `cause` of the generated exception (accessible via
896
+ # Exception#cause) is automatically set to the "current" exception (`$!`), if
897
+ # any. An alternative value, either an `Exception` object or `nil`, can be
898
+ # specified via the `:cause` argument.
899
+ #
900
+ # Exceptions are caught by the `rescue` clause of `begin...end` blocks.
901
+ #
902
+ # raise "Failed to create socket"
903
+ # raise ArgumentError, "No parameters", caller
904
+ #
243
905
  alias raise fail
906
+
244
907
  alias self.raise self.fail
245
908
 
909
+ # <!-- rdoc-file=object.c -->
910
+ # Returns the string resulting from applying *format_string* to any additional
911
+ # arguments. Within the format string, any characters other than format
912
+ # sequences are copied to the result.
913
+ #
914
+ # The syntax of a format sequence is as follows.
915
+ #
916
+ # %[flags][width][.precision]type
917
+ #
918
+ # A format sequence consists of a percent sign, followed by optional flags,
919
+ # width, and precision indicators, then terminated with a field type character.
920
+ # The field type controls how the corresponding `sprintf` argument is to be
921
+ # interpreted, while the flags modify that interpretation.
922
+ #
923
+ # The field type characters are:
924
+ #
925
+ # Field | Integer Format
926
+ # ------+--------------------------------------------------------------
927
+ # b | Convert argument as a binary number.
928
+ # | Negative numbers will be displayed as a two's complement
929
+ # | prefixed with `..1'.
930
+ # B | Equivalent to `b', but uses an uppercase 0B for prefix
931
+ # | in the alternative format by #.
932
+ # d | Convert argument as a decimal number.
933
+ # i | Identical to `d'.
934
+ # o | Convert argument as an octal number.
935
+ # | Negative numbers will be displayed as a two's complement
936
+ # | prefixed with `..7'.
937
+ # u | Identical to `d'.
938
+ # x | Convert argument as a hexadecimal number.
939
+ # | Negative numbers will be displayed as a two's complement
940
+ # | prefixed with `..f' (representing an infinite string of
941
+ # | leading 'ff's).
942
+ # X | Equivalent to `x', but uses uppercase letters.
943
+ #
944
+ # Field | Float Format
945
+ # ------+--------------------------------------------------------------
946
+ # e | Convert floating point argument into exponential notation
947
+ # | with one digit before the decimal point as [-]d.dddddde[+-]dd.
948
+ # | The precision specifies the number of digits after the decimal
949
+ # | point (defaulting to six).
950
+ # E | Equivalent to `e', but uses an uppercase E to indicate
951
+ # | the exponent.
952
+ # f | Convert floating point argument as [-]ddd.dddddd,
953
+ # | where the precision specifies the number of digits after
954
+ # | the decimal point.
955
+ # g | Convert a floating point number using exponential form
956
+ # | if the exponent is less than -4 or greater than or
957
+ # | equal to the precision, or in dd.dddd form otherwise.
958
+ # | The precision specifies the number of significant digits.
959
+ # G | Equivalent to `g', but use an uppercase `E' in exponent form.
960
+ # a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
961
+ # | which is consisted from optional sign, "0x", fraction part
962
+ # | as hexadecimal, "p", and exponential part as decimal.
963
+ # A | Equivalent to `a', but use uppercase `X' and `P'.
964
+ #
965
+ # Field | Other Format
966
+ # ------+--------------------------------------------------------------
967
+ # c | Argument is the numeric code for a single character or
968
+ # | a single character string itself.
969
+ # p | The valuing of argument.inspect.
970
+ # s | Argument is a string to be substituted. If the format
971
+ # | sequence contains a precision, at most that many characters
972
+ # | will be copied.
973
+ # % | A percent sign itself will be displayed. No argument taken.
974
+ #
975
+ # The flags modifies the behavior of the formats. The flag characters are:
976
+ #
977
+ # Flag | Applies to | Meaning
978
+ # ---------+---------------+-----------------------------------------
979
+ # space | bBdiouxX | Leave a space at the start of
980
+ # | aAeEfgG | non-negative numbers.
981
+ # | (numeric fmt) | For `o', `x', `X', `b' and `B', use
982
+ # | | a minus sign with absolute value for
983
+ # | | negative values.
984
+ # ---------+---------------+-----------------------------------------
985
+ # (digit)$ | all | Specifies the absolute argument number
986
+ # | | for this field. Absolute and relative
987
+ # | | argument numbers cannot be mixed in a
988
+ # | | sprintf string.
989
+ # ---------+---------------+-----------------------------------------
990
+ # # | bBoxX | Use an alternative format.
991
+ # | aAeEfgG | For the conversions `o', increase the precision
992
+ # | | until the first digit will be `0' if
993
+ # | | it is not formatted as complements.
994
+ # | | For the conversions `x', `X', `b' and `B'
995
+ # | | on non-zero, prefix the result with ``0x'',
996
+ # | | ``0X'', ``0b'' and ``0B'', respectively.
997
+ # | | For `a', `A', `e', `E', `f', `g', and 'G',
998
+ # | | force a decimal point to be added,
999
+ # | | even if no digits follow.
1000
+ # | | For `g' and 'G', do not remove trailing zeros.
1001
+ # ---------+---------------+-----------------------------------------
1002
+ # + | bBdiouxX | Add a leading plus sign to non-negative
1003
+ # | aAeEfgG | numbers.
1004
+ # | (numeric fmt) | For `o', `x', `X', `b' and `B', use
1005
+ # | | a minus sign with absolute value for
1006
+ # | | negative values.
1007
+ # ---------+---------------+-----------------------------------------
1008
+ # - | all | Left-justify the result of this conversion.
1009
+ # ---------+---------------+-----------------------------------------
1010
+ # 0 (zero) | bBdiouxX | Pad with zeros, not spaces.
1011
+ # | aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
1012
+ # | (numeric fmt) | is used for negative numbers formatted as
1013
+ # | | complements.
1014
+ # ---------+---------------+-----------------------------------------
1015
+ # * | all | Use the next argument as the field width.
1016
+ # | | If negative, left-justify the result. If the
1017
+ # | | asterisk is followed by a number and a dollar
1018
+ # | | sign, use the indicated argument as the width.
1019
+ #
1020
+ # Examples of flags:
1021
+ #
1022
+ # # `+' and space flag specifies the sign of non-negative numbers.
1023
+ # sprintf("%d", 123) #=> "123"
1024
+ # sprintf("%+d", 123) #=> "+123"
1025
+ # sprintf("% d", 123) #=> " 123"
1026
+ #
1027
+ # # `#' flag for `o' increases number of digits to show `0'.
1028
+ # # `+' and space flag changes format of negative numbers.
1029
+ # sprintf("%o", 123) #=> "173"
1030
+ # sprintf("%#o", 123) #=> "0173"
1031
+ # sprintf("%+o", -123) #=> "-173"
1032
+ # sprintf("%o", -123) #=> "..7605"
1033
+ # sprintf("%#o", -123) #=> "..7605"
1034
+ #
1035
+ # # `#' flag for `x' add a prefix `0x' for non-zero numbers.
1036
+ # # `+' and space flag disables complements for negative numbers.
1037
+ # sprintf("%x", 123) #=> "7b"
1038
+ # sprintf("%#x", 123) #=> "0x7b"
1039
+ # sprintf("%+x", -123) #=> "-7b"
1040
+ # sprintf("%x", -123) #=> "..f85"
1041
+ # sprintf("%#x", -123) #=> "0x..f85"
1042
+ # sprintf("%#x", 0) #=> "0"
1043
+ #
1044
+ # # `#' for `X' uses the prefix `0X'.
1045
+ # sprintf("%X", 123) #=> "7B"
1046
+ # sprintf("%#X", 123) #=> "0X7B"
1047
+ #
1048
+ # # `#' flag for `b' add a prefix `0b' for non-zero numbers.
1049
+ # # `+' and space flag disables complements for negative numbers.
1050
+ # sprintf("%b", 123) #=> "1111011"
1051
+ # sprintf("%#b", 123) #=> "0b1111011"
1052
+ # sprintf("%+b", -123) #=> "-1111011"
1053
+ # sprintf("%b", -123) #=> "..10000101"
1054
+ # sprintf("%#b", -123) #=> "0b..10000101"
1055
+ # sprintf("%#b", 0) #=> "0"
1056
+ #
1057
+ # # `#' for `B' uses the prefix `0B'.
1058
+ # sprintf("%B", 123) #=> "1111011"
1059
+ # sprintf("%#B", 123) #=> "0B1111011"
1060
+ #
1061
+ # # `#' for `e' forces to show the decimal point.
1062
+ # sprintf("%.0e", 1) #=> "1e+00"
1063
+ # sprintf("%#.0e", 1) #=> "1.e+00"
1064
+ #
1065
+ # # `#' for `f' forces to show the decimal point.
1066
+ # sprintf("%.0f", 1234) #=> "1234"
1067
+ # sprintf("%#.0f", 1234) #=> "1234."
1068
+ #
1069
+ # # `#' for `g' forces to show the decimal point.
1070
+ # # It also disables stripping lowest zeros.
1071
+ # sprintf("%g", 123.4) #=> "123.4"
1072
+ # sprintf("%#g", 123.4) #=> "123.400"
1073
+ # sprintf("%g", 123456) #=> "123456"
1074
+ # sprintf("%#g", 123456) #=> "123456."
1075
+ #
1076
+ # The field width is an optional integer, followed optionally by a period and a
1077
+ # precision. The width specifies the minimum number of characters that will be
1078
+ # written to the result for this field.
1079
+ #
1080
+ # Examples of width:
1081
+ #
1082
+ # # padding is done by spaces, width=20
1083
+ # # 0 or radix-1. <------------------>
1084
+ # sprintf("%20d", 123) #=> " 123"
1085
+ # sprintf("%+20d", 123) #=> " +123"
1086
+ # sprintf("%020d", 123) #=> "00000000000000000123"
1087
+ # sprintf("%+020d", 123) #=> "+0000000000000000123"
1088
+ # sprintf("% 020d", 123) #=> " 0000000000000000123"
1089
+ # sprintf("%-20d", 123) #=> "123 "
1090
+ # sprintf("%-+20d", 123) #=> "+123 "
1091
+ # sprintf("%- 20d", 123) #=> " 123 "
1092
+ # sprintf("%020x", -123) #=> "..ffffffffffffffff85"
1093
+ #
1094
+ # For numeric fields, the precision controls the number of decimal places
1095
+ # displayed. For string fields, the precision determines the maximum number of
1096
+ # characters to be copied from the string. (Thus, the format sequence `%10.10s`
1097
+ # will always contribute exactly ten characters to the result.)
1098
+ #
1099
+ # Examples of precisions:
1100
+ #
1101
+ # # precision for `d', 'o', 'x' and 'b' is
1102
+ # # minimum number of digits <------>
1103
+ # sprintf("%20.8d", 123) #=> " 00000123"
1104
+ # sprintf("%20.8o", 123) #=> " 00000173"
1105
+ # sprintf("%20.8x", 123) #=> " 0000007b"
1106
+ # sprintf("%20.8b", 123) #=> " 01111011"
1107
+ # sprintf("%20.8d", -123) #=> " -00000123"
1108
+ # sprintf("%20.8o", -123) #=> " ..777605"
1109
+ # sprintf("%20.8x", -123) #=> " ..ffff85"
1110
+ # sprintf("%20.8b", -11) #=> " ..110101"
1111
+ #
1112
+ # # "0x" and "0b" for `#x' and `#b' is not counted for
1113
+ # # precision but "0" for `#o' is counted. <------>
1114
+ # sprintf("%#20.8d", 123) #=> " 00000123"
1115
+ # sprintf("%#20.8o", 123) #=> " 00000173"
1116
+ # sprintf("%#20.8x", 123) #=> " 0x0000007b"
1117
+ # sprintf("%#20.8b", 123) #=> " 0b01111011"
1118
+ # sprintf("%#20.8d", -123) #=> " -00000123"
1119
+ # sprintf("%#20.8o", -123) #=> " ..777605"
1120
+ # sprintf("%#20.8x", -123) #=> " 0x..ffff85"
1121
+ # sprintf("%#20.8b", -11) #=> " 0b..110101"
1122
+ #
1123
+ # # precision for `e' is number of
1124
+ # # digits after the decimal point <------>
1125
+ # sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
1126
+ #
1127
+ # # precision for `f' is number of
1128
+ # # digits after the decimal point <------>
1129
+ # sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
1130
+ #
1131
+ # # precision for `g' is number of
1132
+ # # significant digits <------->
1133
+ # sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
1134
+ #
1135
+ # # <------->
1136
+ # sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
1137
+ #
1138
+ # # precision for `s' is
1139
+ # # maximum number of characters <------>
1140
+ # sprintf("%20.8s", "string test") #=> " string t"
1141
+ #
1142
+ # Examples:
1143
+ #
1144
+ # sprintf("%d %04x", 123, 123) #=> "123 007b"
1145
+ # sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
1146
+ # sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
1147
+ # sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
1148
+ # sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
1149
+ # sprintf("%u", -123) #=> "-123"
1150
+ #
1151
+ # For more complex formatting, Ruby supports a reference by name. %<name>s style
1152
+ # uses format style, but %{name} style doesn't.
1153
+ #
1154
+ # Examples:
1155
+ # sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
1156
+ # #=> 1 : 2.000000
1157
+ # sprintf("%{foo}f", { :foo => 1 })
1158
+ # # => "1f"
1159
+ #
246
1160
  def self?.format: (String format, *untyped args) -> String
1161
+
1162
+ # <!--
1163
+ # rdoc-file=object.c
1164
+ # - format(format_string [, arguments...] ) -> string
1165
+ # - sprintf(format_string [, arguments...] ) -> string
1166
+ # -->
1167
+ # Returns the string resulting from applying *format_string* to any additional
1168
+ # arguments. Within the format string, any characters other than format
1169
+ # sequences are copied to the result.
1170
+ #
1171
+ # The syntax of a format sequence is as follows.
1172
+ #
1173
+ # %[flags][width][.precision]type
1174
+ #
1175
+ # A format sequence consists of a percent sign, followed by optional flags,
1176
+ # width, and precision indicators, then terminated with a field type character.
1177
+ # The field type controls how the corresponding `sprintf` argument is to be
1178
+ # interpreted, while the flags modify that interpretation.
1179
+ #
1180
+ # The field type characters are:
1181
+ #
1182
+ # Field | Integer Format
1183
+ # ------+--------------------------------------------------------------
1184
+ # b | Convert argument as a binary number.
1185
+ # | Negative numbers will be displayed as a two's complement
1186
+ # | prefixed with `..1'.
1187
+ # B | Equivalent to `b', but uses an uppercase 0B for prefix
1188
+ # | in the alternative format by #.
1189
+ # d | Convert argument as a decimal number.
1190
+ # i | Identical to `d'.
1191
+ # o | Convert argument as an octal number.
1192
+ # | Negative numbers will be displayed as a two's complement
1193
+ # | prefixed with `..7'.
1194
+ # u | Identical to `d'.
1195
+ # x | Convert argument as a hexadecimal number.
1196
+ # | Negative numbers will be displayed as a two's complement
1197
+ # | prefixed with `..f' (representing an infinite string of
1198
+ # | leading 'ff's).
1199
+ # X | Equivalent to `x', but uses uppercase letters.
1200
+ #
1201
+ # Field | Float Format
1202
+ # ------+--------------------------------------------------------------
1203
+ # e | Convert floating point argument into exponential notation
1204
+ # | with one digit before the decimal point as [-]d.dddddde[+-]dd.
1205
+ # | The precision specifies the number of digits after the decimal
1206
+ # | point (defaulting to six).
1207
+ # E | Equivalent to `e', but uses an uppercase E to indicate
1208
+ # | the exponent.
1209
+ # f | Convert floating point argument as [-]ddd.dddddd,
1210
+ # | where the precision specifies the number of digits after
1211
+ # | the decimal point.
1212
+ # g | Convert a floating point number using exponential form
1213
+ # | if the exponent is less than -4 or greater than or
1214
+ # | equal to the precision, or in dd.dddd form otherwise.
1215
+ # | The precision specifies the number of significant digits.
1216
+ # G | Equivalent to `g', but use an uppercase `E' in exponent form.
1217
+ # a | Convert floating point argument as [-]0xh.hhhhp[+-]dd,
1218
+ # | which is consisted from optional sign, "0x", fraction part
1219
+ # | as hexadecimal, "p", and exponential part as decimal.
1220
+ # A | Equivalent to `a', but use uppercase `X' and `P'.
1221
+ #
1222
+ # Field | Other Format
1223
+ # ------+--------------------------------------------------------------
1224
+ # c | Argument is the numeric code for a single character or
1225
+ # | a single character string itself.
1226
+ # p | The valuing of argument.inspect.
1227
+ # s | Argument is a string to be substituted. If the format
1228
+ # | sequence contains a precision, at most that many characters
1229
+ # | will be copied.
1230
+ # % | A percent sign itself will be displayed. No argument taken.
1231
+ #
1232
+ # The flags modifies the behavior of the formats. The flag characters are:
1233
+ #
1234
+ # Flag | Applies to | Meaning
1235
+ # ---------+---------------+-----------------------------------------
1236
+ # space | bBdiouxX | Leave a space at the start of
1237
+ # | aAeEfgG | non-negative numbers.
1238
+ # | (numeric fmt) | For `o', `x', `X', `b' and `B', use
1239
+ # | | a minus sign with absolute value for
1240
+ # | | negative values.
1241
+ # ---------+---------------+-----------------------------------------
1242
+ # (digit)$ | all | Specifies the absolute argument number
1243
+ # | | for this field. Absolute and relative
1244
+ # | | argument numbers cannot be mixed in a
1245
+ # | | sprintf string.
1246
+ # ---------+---------------+-----------------------------------------
1247
+ # # | bBoxX | Use an alternative format.
1248
+ # | aAeEfgG | For the conversions `o', increase the precision
1249
+ # | | until the first digit will be `0' if
1250
+ # | | it is not formatted as complements.
1251
+ # | | For the conversions `x', `X', `b' and `B'
1252
+ # | | on non-zero, prefix the result with ``0x'',
1253
+ # | | ``0X'', ``0b'' and ``0B'', respectively.
1254
+ # | | For `a', `A', `e', `E', `f', `g', and 'G',
1255
+ # | | force a decimal point to be added,
1256
+ # | | even if no digits follow.
1257
+ # | | For `g' and 'G', do not remove trailing zeros.
1258
+ # ---------+---------------+-----------------------------------------
1259
+ # + | bBdiouxX | Add a leading plus sign to non-negative
1260
+ # | aAeEfgG | numbers.
1261
+ # | (numeric fmt) | For `o', `x', `X', `b' and `B', use
1262
+ # | | a minus sign with absolute value for
1263
+ # | | negative values.
1264
+ # ---------+---------------+-----------------------------------------
1265
+ # - | all | Left-justify the result of this conversion.
1266
+ # ---------+---------------+-----------------------------------------
1267
+ # 0 (zero) | bBdiouxX | Pad with zeros, not spaces.
1268
+ # | aAeEfgG | For `o', `x', `X', `b' and `B', radix-1
1269
+ # | (numeric fmt) | is used for negative numbers formatted as
1270
+ # | | complements.
1271
+ # ---------+---------------+-----------------------------------------
1272
+ # * | all | Use the next argument as the field width.
1273
+ # | | If negative, left-justify the result. If the
1274
+ # | | asterisk is followed by a number and a dollar
1275
+ # | | sign, use the indicated argument as the width.
1276
+ #
1277
+ # Examples of flags:
1278
+ #
1279
+ # # `+' and space flag specifies the sign of non-negative numbers.
1280
+ # sprintf("%d", 123) #=> "123"
1281
+ # sprintf("%+d", 123) #=> "+123"
1282
+ # sprintf("% d", 123) #=> " 123"
1283
+ #
1284
+ # # `#' flag for `o' increases number of digits to show `0'.
1285
+ # # `+' and space flag changes format of negative numbers.
1286
+ # sprintf("%o", 123) #=> "173"
1287
+ # sprintf("%#o", 123) #=> "0173"
1288
+ # sprintf("%+o", -123) #=> "-173"
1289
+ # sprintf("%o", -123) #=> "..7605"
1290
+ # sprintf("%#o", -123) #=> "..7605"
1291
+ #
1292
+ # # `#' flag for `x' add a prefix `0x' for non-zero numbers.
1293
+ # # `+' and space flag disables complements for negative numbers.
1294
+ # sprintf("%x", 123) #=> "7b"
1295
+ # sprintf("%#x", 123) #=> "0x7b"
1296
+ # sprintf("%+x", -123) #=> "-7b"
1297
+ # sprintf("%x", -123) #=> "..f85"
1298
+ # sprintf("%#x", -123) #=> "0x..f85"
1299
+ # sprintf("%#x", 0) #=> "0"
1300
+ #
1301
+ # # `#' for `X' uses the prefix `0X'.
1302
+ # sprintf("%X", 123) #=> "7B"
1303
+ # sprintf("%#X", 123) #=> "0X7B"
1304
+ #
1305
+ # # `#' flag for `b' add a prefix `0b' for non-zero numbers.
1306
+ # # `+' and space flag disables complements for negative numbers.
1307
+ # sprintf("%b", 123) #=> "1111011"
1308
+ # sprintf("%#b", 123) #=> "0b1111011"
1309
+ # sprintf("%+b", -123) #=> "-1111011"
1310
+ # sprintf("%b", -123) #=> "..10000101"
1311
+ # sprintf("%#b", -123) #=> "0b..10000101"
1312
+ # sprintf("%#b", 0) #=> "0"
1313
+ #
1314
+ # # `#' for `B' uses the prefix `0B'.
1315
+ # sprintf("%B", 123) #=> "1111011"
1316
+ # sprintf("%#B", 123) #=> "0B1111011"
1317
+ #
1318
+ # # `#' for `e' forces to show the decimal point.
1319
+ # sprintf("%.0e", 1) #=> "1e+00"
1320
+ # sprintf("%#.0e", 1) #=> "1.e+00"
1321
+ #
1322
+ # # `#' for `f' forces to show the decimal point.
1323
+ # sprintf("%.0f", 1234) #=> "1234"
1324
+ # sprintf("%#.0f", 1234) #=> "1234."
1325
+ #
1326
+ # # `#' for `g' forces to show the decimal point.
1327
+ # # It also disables stripping lowest zeros.
1328
+ # sprintf("%g", 123.4) #=> "123.4"
1329
+ # sprintf("%#g", 123.4) #=> "123.400"
1330
+ # sprintf("%g", 123456) #=> "123456"
1331
+ # sprintf("%#g", 123456) #=> "123456."
1332
+ #
1333
+ # The field width is an optional integer, followed optionally by a period and a
1334
+ # precision. The width specifies the minimum number of characters that will be
1335
+ # written to the result for this field.
1336
+ #
1337
+ # Examples of width:
1338
+ #
1339
+ # # padding is done by spaces, width=20
1340
+ # # 0 or radix-1. <------------------>
1341
+ # sprintf("%20d", 123) #=> " 123"
1342
+ # sprintf("%+20d", 123) #=> " +123"
1343
+ # sprintf("%020d", 123) #=> "00000000000000000123"
1344
+ # sprintf("%+020d", 123) #=> "+0000000000000000123"
1345
+ # sprintf("% 020d", 123) #=> " 0000000000000000123"
1346
+ # sprintf("%-20d", 123) #=> "123 "
1347
+ # sprintf("%-+20d", 123) #=> "+123 "
1348
+ # sprintf("%- 20d", 123) #=> " 123 "
1349
+ # sprintf("%020x", -123) #=> "..ffffffffffffffff85"
1350
+ #
1351
+ # For numeric fields, the precision controls the number of decimal places
1352
+ # displayed. For string fields, the precision determines the maximum number of
1353
+ # characters to be copied from the string. (Thus, the format sequence `%10.10s`
1354
+ # will always contribute exactly ten characters to the result.)
1355
+ #
1356
+ # Examples of precisions:
1357
+ #
1358
+ # # precision for `d', 'o', 'x' and 'b' is
1359
+ # # minimum number of digits <------>
1360
+ # sprintf("%20.8d", 123) #=> " 00000123"
1361
+ # sprintf("%20.8o", 123) #=> " 00000173"
1362
+ # sprintf("%20.8x", 123) #=> " 0000007b"
1363
+ # sprintf("%20.8b", 123) #=> " 01111011"
1364
+ # sprintf("%20.8d", -123) #=> " -00000123"
1365
+ # sprintf("%20.8o", -123) #=> " ..777605"
1366
+ # sprintf("%20.8x", -123) #=> " ..ffff85"
1367
+ # sprintf("%20.8b", -11) #=> " ..110101"
1368
+ #
1369
+ # # "0x" and "0b" for `#x' and `#b' is not counted for
1370
+ # # precision but "0" for `#o' is counted. <------>
1371
+ # sprintf("%#20.8d", 123) #=> " 00000123"
1372
+ # sprintf("%#20.8o", 123) #=> " 00000173"
1373
+ # sprintf("%#20.8x", 123) #=> " 0x0000007b"
1374
+ # sprintf("%#20.8b", 123) #=> " 0b01111011"
1375
+ # sprintf("%#20.8d", -123) #=> " -00000123"
1376
+ # sprintf("%#20.8o", -123) #=> " ..777605"
1377
+ # sprintf("%#20.8x", -123) #=> " 0x..ffff85"
1378
+ # sprintf("%#20.8b", -11) #=> " 0b..110101"
1379
+ #
1380
+ # # precision for `e' is number of
1381
+ # # digits after the decimal point <------>
1382
+ # sprintf("%20.8e", 1234.56789) #=> " 1.23456789e+03"
1383
+ #
1384
+ # # precision for `f' is number of
1385
+ # # digits after the decimal point <------>
1386
+ # sprintf("%20.8f", 1234.56789) #=> " 1234.56789000"
1387
+ #
1388
+ # # precision for `g' is number of
1389
+ # # significant digits <------->
1390
+ # sprintf("%20.8g", 1234.56789) #=> " 1234.5679"
1391
+ #
1392
+ # # <------->
1393
+ # sprintf("%20.8g", 123456789) #=> " 1.2345679e+08"
1394
+ #
1395
+ # # precision for `s' is
1396
+ # # maximum number of characters <------>
1397
+ # sprintf("%20.8s", "string test") #=> " string t"
1398
+ #
1399
+ # Examples:
1400
+ #
1401
+ # sprintf("%d %04x", 123, 123) #=> "123 007b"
1402
+ # sprintf("%08b '%4s'", 123, 123) #=> "01111011 ' 123'"
1403
+ # sprintf("%1$*2$s %2$d %1$s", "hello", 8) #=> " hello 8 hello"
1404
+ # sprintf("%1$*2$s %2$d", "hello", -8) #=> "hello -8"
1405
+ # sprintf("%+g:% g:%-g", 1.23, 1.23, 1.23) #=> "+1.23: 1.23:1.23"
1406
+ # sprintf("%u", -123) #=> "-123"
1407
+ #
1408
+ # For more complex formatting, Ruby supports a reference by name. %<name>s style
1409
+ # uses format style, but %{name} style doesn't.
1410
+ #
1411
+ # Examples:
1412
+ # sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
1413
+ # #=> 1 : 2.000000
1414
+ # sprintf("%{foo}f", { :foo => 1 })
1415
+ # # => "1f"
1416
+ #
247
1417
  alias sprintf format
1418
+
248
1419
  alias self.sprintf self.format
249
1420
 
1421
+ # <!--
1422
+ # rdoc-file=io.c
1423
+ # - gets(sep=$/ [, getline_args]) -> string or nil
1424
+ # - gets(limit [, getline_args]) -> string or nil
1425
+ # - gets(sep, limit [, getline_args]) -> string or nil
1426
+ # -->
1427
+ # Returns (and assigns to `$_`) the next line from the list of files in `ARGV`
1428
+ # (or `$*`), or from standard input if no files are present on the command line.
1429
+ # Returns `nil` at end of file. The optional argument specifies the record
1430
+ # separator. The separator is included with the contents of each record. A
1431
+ # separator of `nil` reads the entire contents, and a zero-length separator
1432
+ # reads the input one paragraph at a time, where paragraphs are divided by two
1433
+ # consecutive newlines. If the first argument is an integer, or optional second
1434
+ # argument is given, the returning string would not be longer than the given
1435
+ # value in bytes. If multiple filenames are present in `ARGV`, `gets(nil)` will
1436
+ # read the contents one file at a time.
1437
+ #
1438
+ # ARGV << "testfile"
1439
+ # print while gets
1440
+ #
1441
+ # *produces:*
1442
+ #
1443
+ # This is line one
1444
+ # This is line two
1445
+ # This is line three
1446
+ # And so on...
1447
+ #
1448
+ # The style of programming using `$_` as an implicit parameter is gradually
1449
+ # losing favor in the Ruby community.
1450
+ #
250
1451
  def self?.gets: (?String arg0, ?Integer arg1) -> String?
251
1452
 
252
- # Returns an array of the names of global variables.
1453
+ # <!--
1454
+ # rdoc-file=eval.c
1455
+ # - global_variables -> array
1456
+ # -->
1457
+ # Returns an array of the names of global variables. This includes special
1458
+ # regexp global variables such as `$~` and `$+`, but does not include the
1459
+ # numbered regexp global variables (`$1`, `$2`, etc.).
1460
+ #
1461
+ # global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
253
1462
  #
254
- # ```ruby
255
- # global_variables.grep /std/ #=> [:$stdin, :$stdout, :$stderr]
256
- # ```
257
1463
  def self?.global_variables: () -> ::Array[Symbol]
258
1464
 
259
- def self?.load: (String filename, ?boolish) -> bool
1465
+ # <!--
1466
+ # rdoc-file=load.c
1467
+ # - load(filename, wrap=false) -> true
1468
+ # -->
1469
+ # Loads and executes the Ruby program in the file *filename*.
1470
+ #
1471
+ # If the filename is an absolute path (e.g. starts with '/'), the file will be
1472
+ # loaded directly using the absolute path.
1473
+ #
1474
+ # If the filename is an explicit relative path (e.g. starts with './' or '../'),
1475
+ # the file will be loaded using the relative path from the current directory.
1476
+ #
1477
+ # Otherwise, the file will be searched for in the library directories listed in
1478
+ # `$LOAD_PATH` (`$:`). If the file is found in a directory, it will attempt to
1479
+ # load the file relative to that directory. If the file is not found in any of
1480
+ # the directories in `$LOAD_PATH`, the file will be loaded using the relative
1481
+ # path from the current directory.
1482
+ #
1483
+ # If the file doesn't exist when there is an attempt to load it, a LoadError
1484
+ # will be raised.
1485
+ #
1486
+ # If the optional *wrap* parameter is `true`, the loaded script will be executed
1487
+ # under an anonymous module, protecting the calling program's global namespace.
1488
+ # If the optional *wrap* parameter is a module, the loaded script will be
1489
+ # executed under the given module. In no circumstance will any local variables
1490
+ # in the loaded file be propagated to the loading environment.
1491
+ #
1492
+ def self?.load: (String filename, ?Module | bool) -> bool
260
1493
 
1494
+ # <!--
1495
+ # rdoc-file=vm_eval.c
1496
+ # - loop { block }
1497
+ # - loop -> an_enumerator
1498
+ # -->
261
1499
  # Repeatedly executes the block.
262
1500
  #
263
1501
  # If no block is given, an enumerator is returned instead.
264
1502
  #
265
- # ```ruby
266
- # loop do
267
- # print "Input: "
268
- # line = gets
269
- # break if !line or line =~ /^qQ/
270
- # # ...
271
- # end
272
- # ```
273
- #
274
- # [StopIteration](https://ruby-doc.org/core-2.6.3/StopIteration.html)
275
- # raised in the block breaks the loop. In this case, loop returns the
276
- # "result" value stored in the exception.
277
- #
278
- # ```ruby
279
- # enum = Enumerator.new { |y|
280
- # y << "one"
281
- # y << "two"
282
- # :ok
283
- # }
284
- #
285
- # result = loop {
286
- # puts enum.next
287
- # } #=> :ok
288
- # ```
1503
+ # loop do
1504
+ # print "Input: "
1505
+ # line = gets
1506
+ # break if !line or line =~ /^qQ/
1507
+ # # ...
1508
+ # end
1509
+ #
1510
+ # StopIteration raised in the block breaks the loop. In this case, loop returns
1511
+ # the "result" value stored in the exception.
1512
+ #
1513
+ # enum = Enumerator.new { |y|
1514
+ # y << "one"
1515
+ # y << "two"
1516
+ # :ok
1517
+ # }
1518
+ #
1519
+ # result = loop {
1520
+ # puts enum.next
1521
+ # } #=> :ok
1522
+ #
289
1523
  def self?.loop: () { (nil) -> untyped } -> bot
290
- | () -> ::Enumerator[nil, bot]
1524
+ | () -> ::Enumerator[nil, bot]
291
1525
 
1526
+ # <!--
1527
+ # rdoc-file=io.c
1528
+ # - open(path [, mode [, perm]] [, opt]) -> io or nil
1529
+ # - open(path [, mode [, perm]] [, opt]) {|io| block } -> obj
1530
+ # -->
1531
+ # Creates an IO object connected to the given stream, file, or subprocess.
1532
+ #
1533
+ # If `path` does not start with a pipe character (`|`), treat it as the name of
1534
+ # a file to open using the specified mode (defaulting to "r").
1535
+ #
1536
+ # The `mode` is either a string or an integer. If it is an integer, it must be
1537
+ # bitwise-or of open(2) flags, such as File::RDWR or File::EXCL. If it is a
1538
+ # string, it is either "fmode", "fmode:ext_enc", or "fmode:ext_enc:int_enc".
1539
+ #
1540
+ # See the documentation of IO.new for full documentation of the `mode` string
1541
+ # directives.
1542
+ #
1543
+ # If a file is being created, its initial permissions may be set using the
1544
+ # `perm` parameter. See File.new and the open(2) and chmod(2) man pages for a
1545
+ # description of permissions.
1546
+ #
1547
+ # If a block is specified, it will be invoked with the IO object as a parameter,
1548
+ # and the IO will be automatically closed when the block terminates. The call
1549
+ # returns the value of the block.
1550
+ #
1551
+ # If `path` starts with a pipe character (`"|"`), a subprocess is created,
1552
+ # connected to the caller by a pair of pipes. The returned IO object may be
1553
+ # used to write to the standard input and read from the standard output of this
1554
+ # subprocess.
1555
+ #
1556
+ # If the command following the pipe is a single minus sign (`"|-"`), Ruby forks,
1557
+ # and this subprocess is connected to the parent. If the command is not `"-"`,
1558
+ # the subprocess runs the command. Note that the command may be processed by
1559
+ # shell if it contains shell metacharacters.
1560
+ #
1561
+ # When the subprocess is Ruby (opened via `"|-"`), the `open` call returns
1562
+ # `nil`. If a block is associated with the open call, that block will run twice
1563
+ # --- once in the parent and once in the child.
1564
+ #
1565
+ # The block parameter will be an IO object in the parent and `nil` in the child.
1566
+ # The parent's `IO` object will be connected to the child's $stdin and $stdout.
1567
+ # The subprocess will be terminated at the end of the block.
1568
+ #
1569
+ # ### Examples
1570
+ #
1571
+ # Reading from "testfile":
1572
+ #
1573
+ # open("testfile") do |f|
1574
+ # print f.gets
1575
+ # end
1576
+ #
1577
+ # Produces:
1578
+ #
1579
+ # This is line one
1580
+ #
1581
+ # Open a subprocess and read its output:
1582
+ #
1583
+ # cmd = open("|date")
1584
+ # print cmd.gets
1585
+ # cmd.close
1586
+ #
1587
+ # Produces:
1588
+ #
1589
+ # Wed Apr 9 08:56:31 CDT 2003
1590
+ #
1591
+ # Open a subprocess running the same Ruby program:
1592
+ #
1593
+ # f = open("|-", "w+")
1594
+ # if f.nil?
1595
+ # puts "in Child"
1596
+ # exit
1597
+ # else
1598
+ # puts "Got: #{f.gets}"
1599
+ # end
1600
+ #
1601
+ # Produces:
1602
+ #
1603
+ # Got: in Child
1604
+ #
1605
+ # Open a subprocess using a block to receive the IO object:
1606
+ #
1607
+ # open "|-" do |f|
1608
+ # if f then
1609
+ # # parent process
1610
+ # puts "Got: #{f.gets}"
1611
+ # else
1612
+ # # child process
1613
+ # puts "in Child"
1614
+ # end
1615
+ # end
1616
+ #
1617
+ # Produces:
1618
+ #
1619
+ # Got: in Child
1620
+ #
292
1621
  def self?.open: (String name, ?String mode, ?Integer perm) -> IO?
293
- | [T] (String name, ?String mode, ?Integer perm) { (IO) -> T } -> T
1622
+ | [T] (String name, ?String mode, ?Integer perm) { (IO) -> T } -> T
294
1623
 
295
- # Prints each object in turn to `$stdout` . If the output field separator
296
- # ( `$,` ) is not `nil`, its contents will appear between each field. If
297
- # the output record separator ( `$\` ) is not `nil`, it will be appended
298
- # to the output. If no arguments are given, prints `$_` . Objects that
299
- # aren’t strings will be converted by calling their `to_s` method.
300
- #
301
- # ```ruby
302
- # print "cat", [1,2,3], 99, "\n"
303
- # $, = ", "
304
- # $\ = "\n"
305
- # print "cat", [1,2,3], 99
306
- # ```
1624
+ # <!--
1625
+ # rdoc-file=io.c
1626
+ # - print(obj, ...) -> nil
1627
+ # -->
1628
+ # Prints each object in turn to `$stdout`. If the output field separator (`$,`)
1629
+ # is not `nil`, its contents will appear between each field. If the output
1630
+ # record separator (`$\`) is not `nil`, it will be appended to the output. If no
1631
+ # arguments are given, prints `$_`. Objects that aren't strings will be
1632
+ # converted by calling their `to_s` method.
1633
+ #
1634
+ # print "cat", [1,2,3], 99, "\n"
1635
+ # $, = ", "
1636
+ # $\ = "\n"
1637
+ # print "cat", [1,2,3], 99
307
1638
  #
308
1639
  # *produces:*
309
1640
  #
310
1641
  # cat12399
311
1642
  # cat, 1, 2, 3, 99
1643
+ #
312
1644
  def self?.print: (*Kernel args) -> nil
313
1645
 
1646
+ # <!--
1647
+ # rdoc-file=io.c
1648
+ # - printf(io, string [, obj ... ]) -> nil
1649
+ # - printf(string [, obj ... ]) -> nil
1650
+ # -->
1651
+ # Equivalent to:
1652
+ # io.write(sprintf(string, obj, ...))
1653
+ #
1654
+ # or
1655
+ # $stdout.write(sprintf(string, obj, ...))
1656
+ #
314
1657
  def self?.printf: (IO arg0, String arg1, *untyped args) -> nil
315
- | (String arg1, *untyped args) -> nil
316
- | -> nil
1658
+ | (String arg1, *untyped args) -> nil
1659
+ | () -> nil
317
1660
 
1661
+ # <!--
1662
+ # rdoc-file=proc.c
1663
+ # - proc { |...| block } -> a_proc
1664
+ # -->
1665
+ # Equivalent to Proc.new.
1666
+ #
318
1667
  def self?.proc: () { () -> untyped } -> Proc
319
1668
 
1669
+ # <!--
1670
+ # rdoc-file=proc.c
1671
+ # - lambda { |...| block } -> a_proc
1672
+ # -->
1673
+ # Equivalent to Proc.new, except the resulting Proc objects check the number of
1674
+ # parameters passed when called.
1675
+ #
320
1676
  def self?.lambda: () { () -> untyped } -> Proc
321
1677
 
1678
+ # <!--
1679
+ # rdoc-file=io.c
1680
+ # - putc(int) -> int
1681
+ # -->
1682
+ # Equivalent to:
1683
+ #
1684
+ # $stdout.putc(int)
1685
+ #
1686
+ # Refer to the documentation for IO#putc for important information regarding
1687
+ # multi-byte characters.
1688
+ #
322
1689
  def self?.putc: (Integer arg0) -> Integer
323
- | (String arg0) -> String
1690
+ | (String arg0) -> String
324
1691
 
1692
+ # <!--
1693
+ # rdoc-file=io.c
1694
+ # - puts(obj, ...) -> nil
1695
+ # -->
1696
+ # Equivalent to
1697
+ #
1698
+ # $stdout.puts(obj, ...)
1699
+ #
325
1700
  def self?.puts: (*untyped arg0) -> NilClass
326
1701
 
1702
+ # <!--
1703
+ # rdoc-file=io.c
1704
+ # - p(obj) -> obj
1705
+ # - p(obj1, obj2, ...) -> [obj, ...]
1706
+ # - p() -> nil
1707
+ # -->
1708
+ # For each object, directly writes *obj*.`inspect` followed by a newline to the
1709
+ # program's standard output.
1710
+ #
1711
+ # S = Struct.new(:name, :state)
1712
+ # s = S['dave', 'TX']
1713
+ # p s
1714
+ #
1715
+ # *produces:*
1716
+ #
1717
+ # #<S name="dave", state="TX">
1718
+ #
327
1719
  def self?.p: [T] (T arg0) -> T
328
- | (*untyped arg0) -> Array[untyped]
1720
+ | (*untyped arg0) -> Array[untyped]
329
1721
 
1722
+ # <!--
1723
+ # rdoc-file=lib/pp.rb
1724
+ # - pp(*objs)
1725
+ # -->
1726
+ # prints arguments in pretty form.
1727
+ #
1728
+ # pp returns argument(s).
1729
+ #
330
1730
  def self?.pp: [T] (T arg0) -> T
331
- | (*untyped arg0) -> Array[untyped]
1731
+ | (*untyped arg0) -> Array[untyped]
332
1732
 
333
- # If called without an argument, or if `max.to_i.abs == 0`, rand returns
334
- # a pseudo-random floating point number between 0.0 and 1.0, including 0.0
335
- # and excluding 1.0.
1733
+ # <!--
1734
+ # rdoc-file=random.c
1735
+ # - rand(max=0) -> number
1736
+ # -->
1737
+ # If called without an argument, or if `max.to_i.abs == 0`, rand returns a
1738
+ # pseudo-random floating point number between 0.0 and 1.0, including 0.0 and
1739
+ # excluding 1.0.
336
1740
  #
337
- # ```ruby
338
- # rand #=> 0.2725926052826416
339
- # ```
1741
+ # rand #=> 0.2725926052826416
340
1742
  #
341
- # When `max.abs` is greater than or equal to 1, `rand` returns a
342
- # pseudo-random integer greater than or equal to 0 and less than
343
- # `max.to_i.abs` .
1743
+ # When `max.abs` is greater than or equal to 1, `rand` returns a pseudo-random
1744
+ # integer greater than or equal to 0 and less than `max.to_i.abs`.
344
1745
  #
345
- # ```ruby
346
- # rand(100) #=> 12
347
- # ```
1746
+ # rand(100) #=> 12
348
1747
  #
349
- # When `max` is a [Range](https://ruby-doc.org/core-2.6.3/Range.html),
350
- # `rand` returns a random number where range.member?(number) == true.
1748
+ # When `max` is a Range, `rand` returns a random number where
1749
+ # range.member?(number) == true.
351
1750
  #
352
1751
  # Negative or floating point values for `max` are allowed, but may give
353
1752
  # surprising results.
354
1753
  #
355
- # ```ruby
356
- # rand(-100) # => 87
357
- # rand(-0.5) # => 0.8130921818028143
358
- # rand(1.9) # equivalent to rand(1), which is always 0
359
- # ```
1754
+ # rand(-100) # => 87
1755
+ # rand(-0.5) # => 0.8130921818028143
1756
+ # rand(1.9) # equivalent to rand(1), which is always 0
1757
+ #
1758
+ # Kernel.srand may be used to ensure that sequences of random numbers are
1759
+ # reproducible between different runs of a program.
360
1760
  #
361
- # [\#srand](Kernel.downloaded.ruby_doc#method-i-srand) may be used to
362
- # ensure that sequences of random numbers are reproducible between
363
- # different runs of a program.
1761
+ # See also Random.rand.
364
1762
  #
365
- # See also
366
- # [Random\#rand](https://ruby-doc.org/core-2.6.3/Random.html#method-i-rand)
367
- # .
368
1763
  def self?.rand: () -> Float
369
- | (Integer arg0) -> Integer
370
- | (::Range[Integer] arg0) -> Integer
371
- | (::Range[Float] arg0) -> Float
1764
+ | (Integer arg0) -> Integer
1765
+ | (::Range[Integer] arg0) -> Integer
1766
+ | (::Range[Float] arg0) -> Float
372
1767
 
1768
+ # <!--
1769
+ # rdoc-file=io.c
1770
+ # - readline(sep=$/) -> string
1771
+ # - readline(limit) -> string
1772
+ # - readline(sep, limit) -> string
1773
+ # -->
1774
+ # Equivalent to Kernel::gets, except `readline` raises `EOFError` at end of
1775
+ # file.
1776
+ #
373
1777
  def self?.readline: (?String arg0, ?Integer arg1) -> String
374
1778
 
1779
+ # <!--
1780
+ # rdoc-file=io.c
1781
+ # - readlines(sep=$/) -> array
1782
+ # - readlines(limit) -> array
1783
+ # - readlines(sep, limit) -> array
1784
+ # -->
1785
+ # Returns an array containing the lines returned by calling `Kernel.gets(*sep*)`
1786
+ # until the end of file.
1787
+ #
375
1788
  def self?.readlines: (?String arg0, ?Integer arg1) -> ::Array[String]
376
1789
 
1790
+ # <!--
1791
+ # rdoc-file=load.c
1792
+ # - require(name) -> true or false
1793
+ # -->
1794
+ # Loads the given `name`, returning `true` if successful and `false` if the
1795
+ # feature is already loaded.
1796
+ #
1797
+ # If the filename neither resolves to an absolute path nor starts with './' or
1798
+ # '../', the file will be searched for in the library directories listed in
1799
+ # `$LOAD_PATH` (`$:`). If the filename starts with './' or '../', resolution is
1800
+ # based on Dir.pwd.
1801
+ #
1802
+ # If the filename has the extension ".rb", it is loaded as a source file; if the
1803
+ # extension is ".so", ".o", or ".dll", or the default shared library extension
1804
+ # on the current platform, Ruby loads the shared library as a Ruby extension.
1805
+ # Otherwise, Ruby tries adding ".rb", ".so", and so on to the name until found.
1806
+ # If the file named cannot be found, a LoadError will be raised.
1807
+ #
1808
+ # For Ruby extensions the filename given may use any shared library extension.
1809
+ # For example, on Linux the socket extension is "socket.so" and `require
1810
+ # 'socket.dll'` will load the socket extension.
1811
+ #
1812
+ # The absolute path of the loaded file is added to `$LOADED_FEATURES` (`$"`). A
1813
+ # file will not be loaded again if its path already appears in `$"`. For
1814
+ # example, `require 'a'; require './a'` will not load `a.rb` again.
1815
+ #
1816
+ # require "my-library.rb"
1817
+ # require "db-driver"
1818
+ #
1819
+ # Any constants or globals within the loaded source file will be available in
1820
+ # the calling program's global namespace. However, local variables will not be
1821
+ # propagated to the loading environment.
1822
+ #
377
1823
  def self?.require: (String path) -> bool
378
1824
 
1825
+ # <!--
1826
+ # rdoc-file=load.c
1827
+ # - require_relative(string) -> true or false
1828
+ # -->
1829
+ # Ruby tries to load the library named *string* relative to the requiring file's
1830
+ # path. If the file's path cannot be determined a LoadError is raised. If a
1831
+ # file is loaded `true` is returned and false otherwise.
1832
+ #
379
1833
  def self?.require_relative: (String feature) -> bool
380
1834
 
1835
+ # <!--
1836
+ # rdoc-file=io.c
1837
+ # - IO.select(read_array [, write_array [, error_array [, timeout]]]) -> array or nil
1838
+ # -->
1839
+ # Calls select(2) system call. It monitors given arrays of IO objects, waits
1840
+ # until one or more of IO objects are ready for reading, are ready for writing,
1841
+ # and have pending exceptions respectively, and returns an array that contains
1842
+ # arrays of those IO objects. It will return `nil` if optional *timeout* value
1843
+ # is given and no IO object is ready in *timeout* seconds.
1844
+ #
1845
+ # IO.select peeks the buffer of IO objects for testing readability. If the IO
1846
+ # buffer is not empty, IO.select immediately notifies readability. This "peek"
1847
+ # only happens for IO objects. It does not happen for IO-like objects such as
1848
+ # OpenSSL::SSL::SSLSocket.
1849
+ #
1850
+ # The best way to use IO.select is invoking it after nonblocking methods such as
1851
+ # #read_nonblock, #write_nonblock, etc. The methods raise an exception which is
1852
+ # extended by IO::WaitReadable or IO::WaitWritable. The modules notify how the
1853
+ # caller should wait with IO.select. If IO::WaitReadable is raised, the caller
1854
+ # should wait for reading. If IO::WaitWritable is raised, the caller should
1855
+ # wait for writing.
1856
+ #
1857
+ # So, blocking read (#readpartial) can be emulated using #read_nonblock and
1858
+ # IO.select as follows:
1859
+ #
1860
+ # begin
1861
+ # result = io_like.read_nonblock(maxlen)
1862
+ # rescue IO::WaitReadable
1863
+ # IO.select([io_like])
1864
+ # retry
1865
+ # rescue IO::WaitWritable
1866
+ # IO.select(nil, [io_like])
1867
+ # retry
1868
+ # end
1869
+ #
1870
+ # Especially, the combination of nonblocking methods and IO.select is preferred
1871
+ # for IO like objects such as OpenSSL::SSL::SSLSocket. It has #to_io method to
1872
+ # return underlying IO object. IO.select calls #to_io to obtain the file
1873
+ # descriptor to wait.
1874
+ #
1875
+ # This means that readability notified by IO.select doesn't mean readability
1876
+ # from OpenSSL::SSL::SSLSocket object.
1877
+ #
1878
+ # The most likely situation is that OpenSSL::SSL::SSLSocket buffers some data.
1879
+ # IO.select doesn't see the buffer. So IO.select can block when
1880
+ # OpenSSL::SSL::SSLSocket#readpartial doesn't block.
1881
+ #
1882
+ # However, several more complicated situations exist.
1883
+ #
1884
+ # SSL is a protocol which is sequence of records. The record consists of
1885
+ # multiple bytes. So, the remote side of SSL sends a partial record, IO.select
1886
+ # notifies readability but OpenSSL::SSL::SSLSocket cannot decrypt a byte and
1887
+ # OpenSSL::SSL::SSLSocket#readpartial will block.
1888
+ #
1889
+ # Also, the remote side can request SSL renegotiation which forces the local SSL
1890
+ # engine to write some data. This means OpenSSL::SSL::SSLSocket#readpartial may
1891
+ # invoke #write system call and it can block. In such a situation,
1892
+ # OpenSSL::SSL::SSLSocket#read_nonblock raises IO::WaitWritable instead of
1893
+ # blocking. So, the caller should wait for ready for writability as above
1894
+ # example.
1895
+ #
1896
+ # The combination of nonblocking methods and IO.select is also useful for
1897
+ # streams such as tty, pipe socket socket when multiple processes read from a
1898
+ # stream.
1899
+ #
1900
+ # Finally, Linux kernel developers don't guarantee that readability of select(2)
1901
+ # means readability of following read(2) even for a single process. See
1902
+ # select(2) manual on GNU/Linux system.
1903
+ #
1904
+ # Invoking IO.select before IO#readpartial works well as usual. However it is
1905
+ # not the best way to use IO.select.
1906
+ #
1907
+ # The writability notified by select(2) doesn't show how many bytes are
1908
+ # writable. IO#write method blocks until given whole string is written. So,
1909
+ # `IO#write(two or more bytes)` can block after writability is notified by
1910
+ # IO.select. IO#write_nonblock is required to avoid the blocking.
1911
+ #
1912
+ # Blocking write (#write) can be emulated using #write_nonblock and IO.select as
1913
+ # follows: IO::WaitReadable should also be rescued for SSL renegotiation in
1914
+ # OpenSSL::SSL::SSLSocket.
1915
+ #
1916
+ # while 0 < string.bytesize
1917
+ # begin
1918
+ # written = io_like.write_nonblock(string)
1919
+ # rescue IO::WaitReadable
1920
+ # IO.select([io_like])
1921
+ # retry
1922
+ # rescue IO::WaitWritable
1923
+ # IO.select(nil, [io_like])
1924
+ # retry
1925
+ # end
1926
+ # string = string.byteslice(written..-1)
1927
+ # end
1928
+ #
1929
+ # ### Parameters
1930
+ # read_array
1931
+ # : an array of IO objects that wait until ready for read
1932
+ # write_array
1933
+ # : an array of IO objects that wait until ready for write
1934
+ # error_array
1935
+ # : an array of IO objects that wait for exceptions
1936
+ # timeout
1937
+ # : a numeric value in second
1938
+ #
1939
+ #
1940
+ # ### Example
1941
+ #
1942
+ # rp, wp = IO.pipe
1943
+ # mesg = "ping "
1944
+ # 100.times {
1945
+ # # IO.select follows IO#read. Not the best way to use IO.select.
1946
+ # rs, ws, = IO.select([rp], [wp])
1947
+ # if r = rs[0]
1948
+ # ret = r.read(5)
1949
+ # print ret
1950
+ # case ret
1951
+ # when /ping/
1952
+ # mesg = "pong\n"
1953
+ # when /pong/
1954
+ # mesg = "ping "
1955
+ # end
1956
+ # end
1957
+ # if w = ws[0]
1958
+ # w.write(mesg)
1959
+ # end
1960
+ # }
1961
+ #
1962
+ # *produces:*
1963
+ #
1964
+ # ping pong
1965
+ # ping pong
1966
+ # ping pong
1967
+ # (snipped)
1968
+ # ping
1969
+ #
381
1970
  def self?.select: (::Array[IO] read, ?::Array[IO] write, ?::Array[IO] error, ?Integer timeout) -> ::Array[String]
382
1971
 
1972
+ # <!--
1973
+ # rdoc-file=process.c
1974
+ # - sleep([duration]) -> integer
1975
+ # -->
1976
+ # Suspends the current thread for *duration* seconds (which may be any number,
1977
+ # including a `Float` with fractional seconds). Returns the actual number of
1978
+ # seconds slept (rounded), which may be less than that asked for if another
1979
+ # thread calls Thread#run. Called without an argument, sleep() will sleep
1980
+ # forever.
1981
+ #
1982
+ # Time.new #=> 2008-03-08 19:56:19 +0900
1983
+ # sleep 1.2 #=> 1
1984
+ # Time.new #=> 2008-03-08 19:56:20 +0900
1985
+ # sleep 1.9 #=> 2
1986
+ # Time.new #=> 2008-03-08 19:56:22 +0900
1987
+ #
383
1988
  def self?.sleep: () -> bot
384
- | (Numeric duration) -> Integer
1989
+ | (Numeric duration) -> Integer
385
1990
 
1991
+ # <!--
1992
+ # rdoc-file=io.c
1993
+ # - syscall(num [, args...]) -> integer
1994
+ # -->
1995
+ # Calls the operating system function identified by *num* and returns the result
1996
+ # of the function or raises SystemCallError if it failed.
1997
+ #
1998
+ # Arguments for the function can follow *num*. They must be either `String`
1999
+ # objects or `Integer` objects. A `String` object is passed as a pointer to the
2000
+ # byte sequence. An `Integer` object is passed as an integer whose bit size is
2001
+ # the same as a pointer. Up to nine parameters may be passed.
2002
+ #
2003
+ # The function identified by *num* is system dependent. On some Unix systems,
2004
+ # the numbers may be obtained from a header file called `syscall.h`.
2005
+ #
2006
+ # syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box
2007
+ #
2008
+ # *produces:*
2009
+ #
2010
+ # hello
2011
+ #
2012
+ # Calling `syscall` on a platform which does not have any way to an arbitrary
2013
+ # system function just fails with NotImplementedError.
2014
+ #
2015
+ # **Note:** `syscall` is essentially unsafe and unportable. Feel free to shoot
2016
+ # your foot. The DL (Fiddle) library is preferred for safer and a bit more
2017
+ # portable programming.
2018
+ #
386
2019
  def self?.syscall: (Integer num, *untyped args) -> untyped
387
2020
 
2021
+ # <!--
2022
+ # rdoc-file=file.c
2023
+ # - test(cmd, file1 [, file2] ) -> obj
2024
+ # -->
2025
+ # Uses the character `cmd` to perform various tests on `file1` (first table
2026
+ # below) or on `file1` and `file2` (second table).
2027
+ #
2028
+ # File tests on a single file:
2029
+ #
2030
+ # Cmd Returns Meaning
2031
+ # "A" | Time | Last access time for file1
2032
+ # "b" | boolean | True if file1 is a block device
2033
+ # "c" | boolean | True if file1 is a character device
2034
+ # "C" | Time | Last change time for file1
2035
+ # "d" | boolean | True if file1 exists and is a directory
2036
+ # "e" | boolean | True if file1 exists
2037
+ # "f" | boolean | True if file1 exists and is a regular file
2038
+ # "g" | boolean | True if file1 has the \CF{setgid} bit
2039
+ # | | set (false under NT)
2040
+ # "G" | boolean | True if file1 exists and has a group
2041
+ # | | ownership equal to the caller's group
2042
+ # "k" | boolean | True if file1 exists and has the sticky bit set
2043
+ # "l" | boolean | True if file1 exists and is a symbolic link
2044
+ # "M" | Time | Last modification time for file1
2045
+ # "o" | boolean | True if file1 exists and is owned by
2046
+ # | | the caller's effective uid
2047
+ # "O" | boolean | True if file1 exists and is owned by
2048
+ # | | the caller's real uid
2049
+ # "p" | boolean | True if file1 exists and is a fifo
2050
+ # "r" | boolean | True if file1 is readable by the effective
2051
+ # | | uid/gid of the caller
2052
+ # "R" | boolean | True if file is readable by the real
2053
+ # | | uid/gid of the caller
2054
+ # "s" | int/nil | If file1 has nonzero size, return the size,
2055
+ # | | otherwise return nil
2056
+ # "S" | boolean | True if file1 exists and is a socket
2057
+ # "u" | boolean | True if file1 has the setuid bit set
2058
+ # "w" | boolean | True if file1 exists and is writable by
2059
+ # | | the effective uid/gid
2060
+ # "W" | boolean | True if file1 exists and is writable by
2061
+ # | | the real uid/gid
2062
+ # "x" | boolean | True if file1 exists and is executable by
2063
+ # | | the effective uid/gid
2064
+ # "X" | boolean | True if file1 exists and is executable by
2065
+ # | | the real uid/gid
2066
+ # "z" | boolean | True if file1 exists and has a zero length
2067
+ #
2068
+ # Tests that take two files:
2069
+ #
2070
+ # "-" | boolean | True if file1 and file2 are identical
2071
+ # "=" | boolean | True if the modification times of file1
2072
+ # | | and file2 are equal
2073
+ # "<" | boolean | True if the modification time of file1
2074
+ # | | is prior to that of file2
2075
+ # ">" | boolean | True if the modification time of file1
2076
+ # | | is after that of file2
2077
+ #
388
2078
  def self?.test: (String | Integer cmd, String | IO file1, ?String | IO file2) -> (TrueClass | FalseClass | Time | nil | Integer)
389
2079
 
2080
+ # <!--
2081
+ # rdoc-file=vm_eval.c
2082
+ # - throw(tag [, obj])
2083
+ # -->
2084
+ # Transfers control to the end of the active `catch` block waiting for *tag*.
2085
+ # Raises `UncaughtThrowError` if there is no `catch` block for the *tag*. The
2086
+ # optional second parameter supplies a return value for the `catch` block, which
2087
+ # otherwise defaults to `nil`. For examples, see Kernel::catch.
2088
+ #
390
2089
  def self?.throw: (Object tag, ?untyped obj) -> bot
391
2090
 
392
- def self?.warn: (*untyped msg, ?uplevel: Integer | nil) -> NilClass
393
-
394
- # Replaces the current process by running the given external *command* ,
395
- # which can take one of the following forms:
2091
+ # <!--
2092
+ # rdoc-file=warning.rb
2093
+ # - warn(*msgs, uplevel: nil, category: nil) -> nil
2094
+ # -->
2095
+ # If warnings have been disabled (for example with the `-W0` flag), does
2096
+ # nothing. Otherwise, converts each of the messages to strings, appends a
2097
+ # newline character to the string if the string does not end in a newline, and
2098
+ # calls Warning.warn with the string.
2099
+ #
2100
+ # warn("warning 1", "warning 2")
2101
+ #
2102
+ # <em>produces:</em>
2103
+ #
2104
+ # warning 1
2105
+ # warning 2
2106
+ #
2107
+ # If the `uplevel` keyword argument is given, the string will be prepended with
2108
+ # information for the given caller frame in the same format used by the
2109
+ # `rb_warn` C function.
396
2110
  #
397
- # - `exec(commandline)`
398
- # command line string which is passed to the standard shell
2111
+ # # In baz.rb
2112
+ # def foo
2113
+ # warn("invalid call to foo", uplevel: 1)
2114
+ # end
399
2115
  #
400
- # - `exec(cmdname, arg1, ...)`
401
- # command name and one or more arguments (no shell)
2116
+ # def bar
2117
+ # foo
2118
+ # end
402
2119
  #
403
- # - `exec([cmdname, argv0], arg1, ...)`
404
- # command name, [argv](https://ruby-doc.org/core-2.6.3/0) and zero or
405
- # more arguments (no shell)
2120
+ # bar
406
2121
  #
407
- # In the first form, the string is taken as a command line that is subject
408
- # to shell expansion before being executed.
2122
+ # <em>produces:</em>
409
2123
  #
410
- # The standard shell always means `"/bin/sh"` on Unix-like systems, same
411
- # as `ENV["RUBYSHELL"]` (or `ENV["COMSPEC"]` on Windows NT series), and
412
- # similar.
2124
+ # baz.rb:6: warning: invalid call to foo
413
2125
  #
414
- # If the string from the first form ( `exec("command")` ) follows these
415
- # simple rules:
2126
+ # If `category` keyword argument is given, passes the category to
2127
+ # `Warning.warn`. The category given must be be one of the following
2128
+ # categories:
416
2129
  #
417
- # - no meta characters
2130
+ # :deprecated
2131
+ # : Used for warning for deprecated functionality that may be removed in the
2132
+ # future.
2133
+ # :experimental
2134
+ # : Used for experimental features that may change in future releases.
418
2135
  #
419
- # - no shell reserved word and no special built-in
2136
+ def self?.warn: (*untyped msg, ?uplevel: Integer | nil) -> NilClass
2137
+
2138
+ # <!--
2139
+ # rdoc-file=process.c
2140
+ # - exec([env,] command... [,options])
2141
+ # -->
2142
+ # Replaces the current process by running the given external *command*, which
2143
+ # can take one of the following forms:
2144
+ #
2145
+ # `exec(commandline)`
2146
+ # : command line string which is passed to the standard shell
2147
+ # `exec(cmdname, arg1, ...)`
2148
+ # : command name and one or more arguments (no shell)
2149
+ # `exec([cmdname, argv0], arg1, ...)`
2150
+ # : command name, [argv](0) and zero or more arguments (no shell)
2151
+ #
2152
+ #
2153
+ # In the first form, the string is taken as a command line that is subject to
2154
+ # shell expansion before being executed.
420
2155
  #
421
- # - Ruby invokes the command directly without shell
2156
+ # The standard shell always means `"/bin/sh"` on Unix-like systems, otherwise,
2157
+ # `ENV["RUBYSHELL"]` or `ENV["COMSPEC"]` on Windows and similar. The command is
2158
+ # passed as an argument to the `"-c"` switch to the shell, except in the case of
2159
+ # `COMSPEC`.
422
2160
  #
423
- # You can force shell invocation by adding “;” to the string (because “;”
424
- # is a meta character).
2161
+ # If the string from the first form (`exec("command")`) follows these simple
2162
+ # rules:
425
2163
  #
426
- # Note that this behavior is observable by pid obtained (return value of
427
- # spawn() and
428
- # [IO\#pid](https://ruby-doc.org/core-2.6.3/IO.html#method-i-pid) for
429
- # [IO.popen](https://ruby-doc.org/core-2.6.3/IO.html#method-c-popen) ) is
430
- # the pid of the invoked command, not shell.
2164
+ # * no meta characters
2165
+ # * not starting with shell reserved word or special built-in
2166
+ # * Ruby invokes the command directly without shell
431
2167
  #
432
- # In the second form ( `exec("command1", "arg1", ...)` ), the first is
433
- # taken as a command name and the rest are passed as parameters to command
434
- # with no shell expansion.
435
2168
  #
436
- # In the third form ( `exec(["command", "argv0"], "arg1", ...)` ),
437
- # starting a two-element array at the beginning of the command, the first
438
- # element is the command to be executed, and the second argument is used
439
- # as the `argv[0]` value, which may show up in process listings.
2169
+ # You can force shell invocation by adding ";" to the string (because ";" is a
2170
+ # meta character).
440
2171
  #
441
- # In order to execute the command, one of the `exec(2)` system calls are
442
- # used, so the running command may inherit some of the environment of the
443
- # original program (including open file descriptors).
2172
+ # Note that this behavior is observable by pid obtained (return value of spawn()
2173
+ # and IO#pid for IO.popen) is the pid of the invoked command, not shell.
444
2174
  #
445
- # This behavior is modified by the given `env` and `options` parameters.
446
- # See ::spawn for details.
2175
+ # In the second form (`exec("command1", "arg1", ...)`), the first is taken as a
2176
+ # command name and the rest are passed as parameters to command with no shell
2177
+ # expansion.
447
2178
  #
448
- # If the command fails to execute (typically `Errno::ENOENT` when it was
449
- # not found) a
450
- # [SystemCallError](https://ruby-doc.org/core-2.6.3/SystemCallError.html)
451
- # exception is raised.
2179
+ # In the third form (`exec(["command", "argv0"], "arg1", ...)`), starting a
2180
+ # two-element array at the beginning of the command, the first element is the
2181
+ # command to be executed, and the second argument is used as the `argv[0]`
2182
+ # value, which may show up in process listings.
452
2183
  #
453
- # This method modifies process attributes according to given `options`
454
- # before `exec(2)` system call. See ::spawn for more details about the
455
- # given `options` .
2184
+ # In order to execute the command, one of the `exec(2)` system calls are used,
2185
+ # so the running command may inherit some of the environment of the original
2186
+ # program (including open file descriptors).
456
2187
  #
457
- # The modified attributes may be retained when `exec(2)` system call
458
- # fails.
2188
+ # This behavior is modified by the given `env` and `options` parameters. See
2189
+ # ::spawn for details.
2190
+ #
2191
+ # If the command fails to execute (typically Errno::ENOENT when it was not
2192
+ # found) a SystemCallError exception is raised.
2193
+ #
2194
+ # This method modifies process attributes according to given `options` before
2195
+ # `exec(2)` system call. See ::spawn for more details about the given `options`.
2196
+ #
2197
+ # The modified attributes may be retained when `exec(2)` system call fails.
459
2198
  #
460
2199
  # For example, hard resource limits are not restorable.
461
2200
  #
462
- # Consider to create a child process using ::spawn or
463
- # [\#system](Kernel.downloaded.ruby_doc#method-i-system) if this is not
464
- # acceptable.
2201
+ # Consider to create a child process using ::spawn or Kernel#system if this is
2202
+ # not acceptable.
2203
+ #
2204
+ # exec "echo *" # echoes list of files in current directory
2205
+ # # never get here
465
2206
  #
466
- # ```ruby
467
- # exec "echo *" # echoes list of files in current directory
468
- # # never get here
2207
+ # exec "echo", "*" # echoes an asterisk
2208
+ # # never get here
469
2209
  #
470
- # exec "echo", "*" # echoes an asterisk
471
- # # never get here
472
- # ```
473
2210
  def self?.exec: (*String args) -> bot
474
2211
 
475
- type redirect_fd = Integer # redirect to the file descriptor in parent process
476
- | :in | :out | :err # standard input / output / error
477
- | IO # the file descriptor specified as io.fileno
478
- | String # redirect to file with open(string, File::RDONLY)
479
- | [String] # # redirect to file with open(string, File::RDONLY)
480
- | [String, string | int] # redirect to file with open(string, open_mode, 0644)
481
- | [String, string | int, int] # redirect to file with open(string, open_mode, perm)
482
- | [:child, int] # redirect to the redirected file descriptor
483
- | :close # close the file descriptor in child process
2212
+ type redirect_fd = Integer | :in | :out | :err | IO | String | [ String ] | [ String, string | int ] | [ String, string | int, int ] | [ :child, int ] | :close
484
2213
 
485
- def self?.spawn: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: (true | Integer), ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> Integer
486
- | (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: (true | Integer), ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> Integer
2214
+ # <!--
2215
+ # rdoc-file=process.c
2216
+ # - spawn([env,] command... [,options]) -> pid
2217
+ # - Process.spawn([env,] command... [,options]) -> pid
2218
+ # -->
2219
+ # spawn executes specified command and return its pid.
2220
+ #
2221
+ # pid = spawn("tar xf ruby-2.0.0-p195.tar.bz2")
2222
+ # Process.wait pid
2223
+ #
2224
+ # pid = spawn(RbConfig.ruby, "-eputs'Hello, world!'")
2225
+ # Process.wait pid
2226
+ #
2227
+ # This method is similar to Kernel#system but it doesn't wait for the command to
2228
+ # finish.
2229
+ #
2230
+ # The parent process should use Process.wait to collect the termination status
2231
+ # of its child or use Process.detach to register disinterest in their status;
2232
+ # otherwise, the operating system may accumulate zombie processes.
2233
+ #
2234
+ # spawn has bunch of options to specify process attributes:
2235
+ #
2236
+ # env: hash
2237
+ # name => val : set the environment variable
2238
+ # name => nil : unset the environment variable
2239
+ #
2240
+ # the keys and the values except for +nil+ must be strings.
2241
+ # command...:
2242
+ # commandline : command line string which is passed to the standard shell
2243
+ # cmdname, arg1, ... : command name and one or more arguments (This form does not use the shell. See below for caveats.)
2244
+ # [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
2245
+ # options: hash
2246
+ # clearing environment variables:
2247
+ # :unsetenv_others => true : clear environment variables except specified by env
2248
+ # :unsetenv_others => false : don't clear (default)
2249
+ # process group:
2250
+ # :pgroup => true or 0 : make a new process group
2251
+ # :pgroup => pgid : join the specified process group
2252
+ # :pgroup => nil : don't change the process group (default)
2253
+ # create new process group: Windows only
2254
+ # :new_pgroup => true : the new process is the root process of a new process group
2255
+ # :new_pgroup => false : don't create a new process group (default)
2256
+ # resource limit: resourcename is core, cpu, data, etc. See Process.setrlimit.
2257
+ # :rlimit_resourcename => limit
2258
+ # :rlimit_resourcename => [cur_limit, max_limit]
2259
+ # umask:
2260
+ # :umask => int
2261
+ # redirection:
2262
+ # key:
2263
+ # FD : single file descriptor in child process
2264
+ # [FD, FD, ...] : multiple file descriptor in child process
2265
+ # value:
2266
+ # FD : redirect to the file descriptor in parent process
2267
+ # string : redirect to file with open(string, "r" or "w")
2268
+ # [string] : redirect to file with open(string, File::RDONLY)
2269
+ # [string, open_mode] : redirect to file with open(string, open_mode, 0644)
2270
+ # [string, open_mode, perm] : redirect to file with open(string, open_mode, perm)
2271
+ # [:child, FD] : redirect to the redirected file descriptor
2272
+ # :close : close the file descriptor in child process
2273
+ # FD is one of follows
2274
+ # :in : the file descriptor 0 which is the standard input
2275
+ # :out : the file descriptor 1 which is the standard output
2276
+ # :err : the file descriptor 2 which is the standard error
2277
+ # integer : the file descriptor of specified the integer
2278
+ # io : the file descriptor specified as io.fileno
2279
+ # file descriptor inheritance: close non-redirected non-standard fds (3, 4, 5, ...) or not
2280
+ # :close_others => false : inherit
2281
+ # current directory:
2282
+ # :chdir => str
2283
+ #
2284
+ # The `cmdname, arg1, ...` form does not use the shell. However, on different
2285
+ # OSes, different things are provided as built-in commands. An example of this
2286
+ # is +'echo'+, which is a built-in on Windows, but is a normal program on Linux
2287
+ # and Mac OS X. This means that `Process.spawn 'echo', '%Path%'` will display
2288
+ # the contents of the `%Path%` environment variable on Windows, but
2289
+ # `Process.spawn 'echo', '$PATH'` prints the literal `$PATH`.
2290
+ #
2291
+ # If a hash is given as `env`, the environment is updated by `env` before
2292
+ # `exec(2)` in the child process. If a pair in `env` has nil as the value, the
2293
+ # variable is deleted.
2294
+ #
2295
+ # # set FOO as BAR and unset BAZ.
2296
+ # pid = spawn({"FOO"=>"BAR", "BAZ"=>nil}, command)
2297
+ #
2298
+ # If a hash is given as `options`, it specifies process group, create new
2299
+ # process group, resource limit, current directory, umask and redirects for the
2300
+ # child process. Also, it can be specified to clear environment variables.
2301
+ #
2302
+ # The `:unsetenv_others` key in `options` specifies to clear environment
2303
+ # variables, other than specified by `env`.
2304
+ #
2305
+ # pid = spawn(command, :unsetenv_others=>true) # no environment variable
2306
+ # pid = spawn({"FOO"=>"BAR"}, command, :unsetenv_others=>true) # FOO only
2307
+ #
2308
+ # The `:pgroup` key in `options` specifies a process group. The corresponding
2309
+ # value should be true, zero, a positive integer, or nil. true and zero cause
2310
+ # the process to be a process leader of a new process group. A non-zero positive
2311
+ # integer causes the process to join the provided process group. The default
2312
+ # value, nil, causes the process to remain in the same process group.
2313
+ #
2314
+ # pid = spawn(command, :pgroup=>true) # process leader
2315
+ # pid = spawn(command, :pgroup=>10) # belongs to the process group 10
2316
+ #
2317
+ # The `:new_pgroup` key in `options` specifies to pass
2318
+ # `CREATE_NEW_PROCESS_GROUP` flag to `CreateProcessW()` that is Windows API.
2319
+ # This option is only for Windows. true means the new process is the root
2320
+ # process of the new process group. The new process has CTRL+C disabled. This
2321
+ # flag is necessary for `Process.kill(:SIGINT, pid)` on the subprocess.
2322
+ # :new_pgroup is false by default.
2323
+ #
2324
+ # pid = spawn(command, :new_pgroup=>true) # new process group
2325
+ # pid = spawn(command, :new_pgroup=>false) # same process group
2326
+ #
2327
+ # The `:rlimit_`*foo* key specifies a resource limit. *foo* should be one of
2328
+ # resource types such as `core`. The corresponding value should be an integer or
2329
+ # an array which have one or two integers: same as cur_limit and max_limit
2330
+ # arguments for Process.setrlimit.
2331
+ #
2332
+ # cur, max = Process.getrlimit(:CORE)
2333
+ # pid = spawn(command, :rlimit_core=>[0,max]) # disable core temporary.
2334
+ # pid = spawn(command, :rlimit_core=>max) # enable core dump
2335
+ # pid = spawn(command, :rlimit_core=>0) # never dump core.
2336
+ #
2337
+ # The `:umask` key in `options` specifies the umask.
2338
+ #
2339
+ # pid = spawn(command, :umask=>077)
2340
+ #
2341
+ # The :in, :out, :err, an integer, an IO and an array key specifies a
2342
+ # redirection. The redirection maps a file descriptor in the child process.
2343
+ #
2344
+ # For example, stderr can be merged into stdout as follows:
2345
+ #
2346
+ # pid = spawn(command, :err=>:out)
2347
+ # pid = spawn(command, 2=>1)
2348
+ # pid = spawn(command, STDERR=>:out)
2349
+ # pid = spawn(command, STDERR=>STDOUT)
2350
+ #
2351
+ # The hash keys specifies a file descriptor in the child process started by
2352
+ # #spawn. :err, 2 and STDERR specifies the standard error stream (stderr).
2353
+ #
2354
+ # The hash values specifies a file descriptor in the parent process which
2355
+ # invokes #spawn. :out, 1 and STDOUT specifies the standard output stream
2356
+ # (stdout).
2357
+ #
2358
+ # In the above example, the standard output in the child process is not
2359
+ # specified. So it is inherited from the parent process.
2360
+ #
2361
+ # The standard input stream (stdin) can be specified by :in, 0 and STDIN.
2362
+ #
2363
+ # A filename can be specified as a hash value.
2364
+ #
2365
+ # pid = spawn(command, :in=>"/dev/null") # read mode
2366
+ # pid = spawn(command, :out=>"/dev/null") # write mode
2367
+ # pid = spawn(command, :err=>"log") # write mode
2368
+ # pid = spawn(command, [:out, :err]=>"/dev/null") # write mode
2369
+ # pid = spawn(command, 3=>"/dev/null") # read mode
2370
+ #
2371
+ # For stdout and stderr (and combination of them), it is opened in write mode.
2372
+ # Otherwise read mode is used.
2373
+ #
2374
+ # For specifying flags and permission of file creation explicitly, an array is
2375
+ # used instead.
2376
+ #
2377
+ # pid = spawn(command, :in=>["file"]) # read mode is assumed
2378
+ # pid = spawn(command, :in=>["file", "r"])
2379
+ # pid = spawn(command, :out=>["log", "w"]) # 0644 assumed
2380
+ # pid = spawn(command, :out=>["log", "w", 0600])
2381
+ # pid = spawn(command, :out=>["log", File::WRONLY|File::EXCL|File::CREAT, 0600])
2382
+ #
2383
+ # The array specifies a filename, flags and permission. The flags can be a
2384
+ # string or an integer. If the flags is omitted or nil, File::RDONLY is assumed.
2385
+ # The permission should be an integer. If the permission is omitted or nil, 0644
2386
+ # is assumed.
2387
+ #
2388
+ # If an array of IOs and integers are specified as a hash key, all the elements
2389
+ # are redirected.
2390
+ #
2391
+ # # stdout and stderr is redirected to log file.
2392
+ # # The file "log" is opened just once.
2393
+ # pid = spawn(command, [:out, :err]=>["log", "w"])
2394
+ #
2395
+ # Another way to merge multiple file descriptors is [:child, fd]. [:child, fd]
2396
+ # means the file descriptor in the child process. This is different from fd. For
2397
+ # example, :err=>:out means redirecting child stderr to parent stdout. But
2398
+ # :err=>[:child, :out] means redirecting child stderr to child stdout. They
2399
+ # differ if stdout is redirected in the child process as follows.
2400
+ #
2401
+ # # stdout and stderr is redirected to log file.
2402
+ # # The file "log" is opened just once.
2403
+ # pid = spawn(command, :out=>["log", "w"], :err=>[:child, :out])
2404
+ #
2405
+ # [:child, :out] can be used to merge stderr into stdout in IO.popen. In this
2406
+ # case, IO.popen redirects stdout to a pipe in the child process and [:child,
2407
+ # :out] refers the redirected stdout.
2408
+ #
2409
+ # io = IO.popen(["sh", "-c", "echo out; echo err >&2", :err=>[:child, :out]])
2410
+ # p io.read #=> "out\nerr\n"
2411
+ #
2412
+ # The `:chdir` key in `options` specifies the current directory.
2413
+ #
2414
+ # pid = spawn(command, :chdir=>"/var/tmp")
2415
+ #
2416
+ # spawn closes all non-standard unspecified descriptors by default. The
2417
+ # "standard" descriptors are 0, 1 and 2. This behavior is specified by
2418
+ # :close_others option. :close_others doesn't affect the standard descriptors
2419
+ # which are closed only if :close is specified explicitly.
2420
+ #
2421
+ # pid = spawn(command, :close_others=>true) # close 3,4,5,... (default)
2422
+ # pid = spawn(command, :close_others=>false) # don't close 3,4,5,...
2423
+ #
2424
+ # :close_others is false by default for spawn and IO.popen.
2425
+ #
2426
+ # Note that fds which close-on-exec flag is already set are closed regardless of
2427
+ # :close_others option.
2428
+ #
2429
+ # So IO.pipe and spawn can be used as IO.popen.
2430
+ #
2431
+ # # similar to r = IO.popen(command)
2432
+ # r, w = IO.pipe
2433
+ # pid = spawn(command, :out=>w) # r, w is closed in the child process.
2434
+ # w.close
2435
+ #
2436
+ # :close is specified as a hash value to close a fd individually.
2437
+ #
2438
+ # f = open(foo)
2439
+ # system(command, f=>:close) # don't inherit f.
2440
+ #
2441
+ # If a file descriptor need to be inherited, io=>io can be used.
2442
+ #
2443
+ # # valgrind has --log-fd option for log destination.
2444
+ # # log_w=>log_w indicates log_w.fileno inherits to child process.
2445
+ # log_r, log_w = IO.pipe
2446
+ # pid = spawn("valgrind", "--log-fd=#{log_w.fileno}", "echo", "a", log_w=>log_w)
2447
+ # log_w.close
2448
+ # p log_r.read
2449
+ #
2450
+ # It is also possible to exchange file descriptors.
2451
+ #
2452
+ # pid = spawn(command, :out=>:err, :err=>:out)
2453
+ #
2454
+ # The hash keys specify file descriptors in the child process. The hash values
2455
+ # specifies file descriptors in the parent process. So the above specifies
2456
+ # exchanging stdout and stderr. Internally, `spawn` uses an extra file
2457
+ # descriptor to resolve such cyclic file descriptor mapping.
2458
+ #
2459
+ # See Kernel.exec for the standard shell.
2460
+ #
2461
+ def self?.spawn: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> Integer
2462
+ | (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> Integer
487
2463
 
488
- # Executes *command…* in a subshell. *command…* is one of following forms.
2464
+ # <!--
2465
+ # rdoc-file=process.c
2466
+ # - system([env,] command... [,options], exception: false) -> true, false or nil
2467
+ # -->
2468
+ # Executes *command...* in a subshell. *command...* is one of following forms.
2469
+ #
2470
+ # `commandline`
2471
+ # : command line string which is passed to the standard shell
2472
+ # `cmdname, arg1, ...`
2473
+ # : command name and one or more arguments (no shell)
2474
+ # `[cmdname, argv0], arg1, ...`
2475
+ # : command name, `argv[0]` and zero or more arguments (no shell)
2476
+ #
2477
+ #
2478
+ # system returns `true` if the command gives zero exit status, `false` for non
2479
+ # zero exit status. Returns `nil` if command execution fails. An error status is
2480
+ # available in `$?`.
489
2481
  #
490
- # commandline : command line string which is passed to the standard shell
491
- # cmdname, arg1, ... : command name and one or more arguments (no shell)
492
- # [cmdname, argv0], arg1, ... : command name, argv[0] and zero or more arguments (no shell)
2482
+ # If the `exception: true` argument is passed, the method raises an exception
2483
+ # instead of returning `false` or `nil`.
493
2484
  #
494
- # system returns `true` if the command gives zero exit status, `false` for
495
- # non zero exit status. Returns `nil` if command execution fails. An error
496
- # status is available in `$?` . The arguments are processed in the same
497
- # way as for `Kernel.spawn` .
2485
+ # The arguments are processed in the same way as for Kernel#spawn.
498
2486
  #
499
- # The hash arguments, env and options, are same as `exec` and `spawn` .
500
- # See `Kernel.spawn` for details.
2487
+ # The hash arguments, env and options, are same as #exec and #spawn. See
2488
+ # Kernel#spawn for details.
501
2489
  #
502
- # ```ruby
503
- # system("echo *")
504
- # system("echo", "*")
505
- # ```
2490
+ # system("echo *")
2491
+ # system("echo", "*")
506
2492
  #
507
2493
  # *produces:*
508
2494
  #
509
2495
  # config.h main.rb
510
2496
  # *
511
2497
  #
512
- # See `Kernel.exec` for the standard shell.
513
- def self?.system: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: (true | Integer), ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> (NilClass | FalseClass | TrueClass)
514
- | (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: (true | Integer), ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> (NilClass | FalseClass | TrueClass)
2498
+ # Error handling:
2499
+ #
2500
+ # system("cat nonexistent.txt")
2501
+ # # => false
2502
+ # system("catt nonexistent.txt")
2503
+ # # => nil
2504
+ #
2505
+ # system("cat nonexistent.txt", exception: true)
2506
+ # # RuntimeError (Command failed with exit 1: cat)
2507
+ # system("catt nonexistent.txt", exception: true)
2508
+ # # Errno::ENOENT (No such file or directory - catt)
2509
+ #
2510
+ # See Kernel#exec for the standard shell.
2511
+ #
2512
+ def self?.system: (String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> (NilClass | FalseClass | TrueClass)
2513
+ | (Hash[string, string?] env, String command, *String args, ?unsetenv_others: boolish, ?pgroup: true | Integer, ?umask: Integer, ?in: redirect_fd, ?out: redirect_fd, ?err: redirect_fd, ?close_others: boolish, ?chdir: String) -> (NilClass | FalseClass | TrueClass)
515
2514
  end
516
2515
 
517
2516
  Kernel::RUBYGEMS_ACTIVATION_MONITOR: untyped