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