rbs 3.0.0.dev.2 → 3.0.0.dev.3
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 +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- data/sig/shims/ripper.rbs +0 -8
data/core/kernel.rbs
CHANGED
|
@@ -12,266 +12,147 @@
|
|
|
12
12
|
#
|
|
13
13
|
# Module Kernel provides methods that are useful for:
|
|
14
14
|
#
|
|
15
|
-
# * [Converting](
|
|
16
|
-
# * [Querying](
|
|
17
|
-
# * [Exiting](
|
|
18
|
-
# * [Exceptions](
|
|
19
|
-
# * [IO](
|
|
20
|
-
# * [Procs](
|
|
21
|
-
# * [Tracing](
|
|
22
|
-
# * [Subprocesses](
|
|
23
|
-
# * [Loading](
|
|
24
|
-
# * [Yielding](
|
|
25
|
-
# * [Random Values](
|
|
26
|
-
# * [Other](
|
|
15
|
+
# * [Converting](rdoc-ref:Kernel@Converting)
|
|
16
|
+
# * [Querying](rdoc-ref:Kernel@Querying)
|
|
17
|
+
# * [Exiting](rdoc-ref:Kernel@Exiting)
|
|
18
|
+
# * [Exceptions](rdoc-ref:Kernel@Exceptions)
|
|
19
|
+
# * [IO](rdoc-ref:Kernel@IO)
|
|
20
|
+
# * [Procs](rdoc-ref:Kernel@Procs)
|
|
21
|
+
# * [Tracing](rdoc-ref:Kernel@Tracing)
|
|
22
|
+
# * [Subprocesses](rdoc-ref:Kernel@Subprocesses)
|
|
23
|
+
# * [Loading](rdoc-ref:Kernel@Loading)
|
|
24
|
+
# * [Yielding](rdoc-ref:Kernel@Yielding)
|
|
25
|
+
# * [Random Values](rdoc-ref:Kernel@Random+Values)
|
|
26
|
+
# * [Other](rdoc-ref:Kernel@Other)
|
|
27
27
|
#
|
|
28
28
|
#
|
|
29
29
|
# ### Converting
|
|
30
30
|
#
|
|
31
|
-
#
|
|
32
|
-
# :
|
|
33
|
-
#
|
|
34
|
-
#
|
|
35
|
-
# :
|
|
36
|
-
#
|
|
37
|
-
#
|
|
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
|
-
#
|
|
31
|
+
# * #Array: Returns an Array based on the given argument.
|
|
32
|
+
# * #Complex: Returns a Complex based on the given arguments.
|
|
33
|
+
# * #Float: Returns a Float based on the given arguments.
|
|
34
|
+
# * #Hash: Returns a Hash based on the given argument.
|
|
35
|
+
# * #Integer: Returns an Integer based on the given arguments.
|
|
36
|
+
# * #Rational: Returns a Rational based on the given arguments.
|
|
37
|
+
# * #String: Returns a String based on the given argument.
|
|
52
38
|
#
|
|
53
39
|
#
|
|
54
40
|
# ### Querying
|
|
55
41
|
#
|
|
56
|
-
#
|
|
57
|
-
# :
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#
|
|
63
|
-
#
|
|
64
|
-
# :
|
|
65
|
-
#
|
|
66
|
-
#
|
|
67
|
-
# :
|
|
68
|
-
#
|
|
69
|
-
#
|
|
70
|
-
# :
|
|
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
|
-
#
|
|
42
|
+
# * #__callee__: Returns the called name of the current method as a symbol.
|
|
43
|
+
# * #__dir__: Returns the path to the directory from which the current method
|
|
44
|
+
# is called.
|
|
45
|
+
# * #__method__: Returns the name of the current method as a symbol.
|
|
46
|
+
# * #autoload?: Returns the file to be loaded when the given module is
|
|
47
|
+
# referenced.
|
|
48
|
+
# * #binding: Returns a Binding for the context at the point of call.
|
|
49
|
+
# * #block_given?: Returns `true` if a block was passed to the calling method.
|
|
50
|
+
# * #caller: Returns the current execution stack as an array of strings.
|
|
51
|
+
# * #caller_locations: Returns the current execution stack as an array of
|
|
52
|
+
# Thread::Backtrace::Location objects.
|
|
53
|
+
# * #class: Returns the class of `self`.
|
|
54
|
+
# * #frozen?: Returns whether `self` is frozen.
|
|
55
|
+
# * #global_variables: Returns an array of global variables as symbols.
|
|
56
|
+
# * #local_variables: Returns an array of local variables as symbols.
|
|
57
|
+
# * #test: Performs specified tests on the given single file or pair of files.
|
|
97
58
|
#
|
|
98
59
|
#
|
|
99
60
|
# ### Exiting
|
|
100
61
|
#
|
|
101
|
-
#
|
|
102
|
-
# :
|
|
103
|
-
#
|
|
104
|
-
#
|
|
105
|
-
#
|
|
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
|
-
#
|
|
62
|
+
# * #abort: Exits the current process after printing the given arguments.
|
|
63
|
+
# * #at_exit: Executes the given block when the process exits.
|
|
64
|
+
# * #exit: Exits the current process after calling any registered `at_exit`
|
|
65
|
+
# handlers.
|
|
66
|
+
# * #exit!: Exits the current process without calling any registered `at_exit`
|
|
67
|
+
# handlers.
|
|
115
68
|
#
|
|
116
69
|
#
|
|
117
70
|
# ### Exceptions
|
|
118
71
|
#
|
|
119
|
-
#
|
|
120
|
-
# :
|
|
121
|
-
#
|
|
122
|
-
#
|
|
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
|
-
#
|
|
72
|
+
# * #catch: Executes the given block, possibly catching a thrown object.
|
|
73
|
+
# * #raise (aliased as #fail): Raises an exception based on the given
|
|
74
|
+
# arguments.
|
|
75
|
+
# * #throw: Returns from the active catch block waiting for the given tag.
|
|
128
76
|
#
|
|
129
77
|
#
|
|
130
78
|
# ### IO
|
|
131
79
|
#
|
|
132
|
-
#
|
|
133
|
-
# :
|
|
134
|
-
#
|
|
135
|
-
#
|
|
136
|
-
# :
|
|
137
|
-
#
|
|
138
|
-
#
|
|
139
|
-
#
|
|
140
|
-
# :
|
|
141
|
-
#
|
|
142
|
-
#
|
|
143
|
-
# :
|
|
144
|
-
#
|
|
145
|
-
#
|
|
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
|
-
#
|
|
80
|
+
# * ::pp: Prints the given objects in pretty form.
|
|
81
|
+
# * #gets: Returns and assigns to `$_` the next line from the current input.
|
|
82
|
+
# * #open: Creates an IO object connected to the given stream, file, or
|
|
83
|
+
# subprocess.
|
|
84
|
+
# * #p: Prints the given objects' inspect output to the standard output.
|
|
85
|
+
# * #print: Prints the given objects to standard output without a newline.
|
|
86
|
+
# * #printf: Prints the string resulting from applying the given format string
|
|
87
|
+
# to any additional arguments.
|
|
88
|
+
# * #putc: Equivalent to <tt.$stdout.putc(object)</tt> for the given object.
|
|
89
|
+
# * #puts: Equivalent to `$stdout.puts(*objects)` for the given objects.
|
|
90
|
+
# * #readline: Similar to #gets, but raises an exception at the end of file.
|
|
91
|
+
# * #readlines: Returns an array of the remaining lines from the current
|
|
92
|
+
# input.
|
|
93
|
+
# * #select: Same as IO.select.
|
|
167
94
|
#
|
|
168
95
|
#
|
|
169
96
|
# ### Procs
|
|
170
97
|
#
|
|
171
|
-
#
|
|
172
|
-
# :
|
|
173
|
-
#
|
|
174
|
-
# #proc
|
|
175
|
-
# : Returns a new Proc; equivalent to Proc.new.
|
|
176
|
-
#
|
|
98
|
+
# * #lambda: Returns a lambda proc for the given block.
|
|
99
|
+
# * #proc: Returns a new Proc; equivalent to Proc.new.
|
|
177
100
|
#
|
|
178
101
|
#
|
|
179
102
|
# ### Tracing
|
|
180
103
|
#
|
|
181
|
-
#
|
|
182
|
-
#
|
|
183
|
-
#
|
|
184
|
-
#
|
|
185
|
-
#
|
|
186
|
-
# : Starts tracing assignments to the given global variable.
|
|
187
|
-
#
|
|
188
|
-
# #untrace_var
|
|
189
|
-
# : Disables tracing of assignments to the given global variable.
|
|
190
|
-
#
|
|
104
|
+
# * #set_trace_func: Sets the given proc as the handler for tracing, or
|
|
105
|
+
# disables tracing if given `nil`.
|
|
106
|
+
# * #trace_var: Starts tracing assignments to the given global variable.
|
|
107
|
+
# * #untrace_var: Disables tracing of assignments to the given global
|
|
108
|
+
# variable.
|
|
191
109
|
#
|
|
192
110
|
#
|
|
193
111
|
# ### Subprocesses
|
|
194
112
|
#
|
|
195
|
-
#
|
|
196
|
-
#
|
|
197
|
-
#
|
|
198
|
-
#
|
|
199
|
-
# :
|
|
200
|
-
#
|
|
201
|
-
#
|
|
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
|
-
#
|
|
113
|
+
# * [\`command`](rdoc-ref:Kernel#`): Returns the standard output of running
|
|
114
|
+
# `command` in a subshell.
|
|
115
|
+
# * #exec: Replaces current process with a new process.
|
|
116
|
+
# * #fork: Forks the current process into two processes.
|
|
117
|
+
# * #spawn: Executes the given command and returns its pid without waiting for
|
|
118
|
+
# completion.
|
|
119
|
+
# * #system: Executes the given command in a subshell.
|
|
211
120
|
#
|
|
212
121
|
#
|
|
213
122
|
# ### Loading
|
|
214
123
|
#
|
|
215
|
-
#
|
|
216
|
-
#
|
|
217
|
-
#
|
|
218
|
-
#
|
|
219
|
-
#
|
|
220
|
-
#
|
|
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
|
-
#
|
|
124
|
+
# * #autoload: Registers the given file to be loaded when the given constant
|
|
125
|
+
# is first referenced.
|
|
126
|
+
# * #load: Loads the given Ruby file.
|
|
127
|
+
# * #require: Loads the given Ruby file unless it has already been loaded.
|
|
128
|
+
# * #require_relative: Loads the Ruby file path relative to the calling file,
|
|
129
|
+
# unless it has already been loaded.
|
|
229
130
|
#
|
|
230
131
|
#
|
|
231
132
|
# ### Yielding
|
|
232
133
|
#
|
|
233
|
-
#
|
|
234
|
-
# :
|
|
235
|
-
#
|
|
236
|
-
# #then (aliased as #yield_self)
|
|
237
|
-
# : Yields `self` to the block and returns the result of the block.
|
|
238
|
-
#
|
|
134
|
+
# * #tap: Yields `self` to the given block; returns `self`.
|
|
135
|
+
# * #then (aliased as #yield_self): Yields `self` to the block and returns the
|
|
136
|
+
# result of the block.
|
|
239
137
|
#
|
|
240
138
|
#
|
|
241
139
|
# ### Random Values
|
|
242
140
|
#
|
|
243
|
-
#
|
|
244
|
-
#
|
|
245
|
-
#
|
|
246
|
-
#
|
|
247
|
-
# #srand
|
|
248
|
-
# : Seeds the pseudo-random number generator with the given number.
|
|
249
|
-
#
|
|
141
|
+
# * #rand: Returns a pseudo-random floating point number strictly between 0.0
|
|
142
|
+
# and 1.0.
|
|
143
|
+
# * #srand: Seeds the pseudo-random number generator with the given number.
|
|
250
144
|
#
|
|
251
145
|
#
|
|
252
146
|
# ### Other
|
|
253
147
|
#
|
|
254
|
-
#
|
|
255
|
-
# :
|
|
256
|
-
#
|
|
257
|
-
#
|
|
258
|
-
#
|
|
259
|
-
#
|
|
260
|
-
#
|
|
261
|
-
# :
|
|
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.
|
|
148
|
+
# * #eval: Evaluates the given string as Ruby code.
|
|
149
|
+
# * #loop: Repeatedly executes the given block.
|
|
150
|
+
# * #sleep: Suspends the current thread for the given number of seconds.
|
|
151
|
+
# * #sprintf (aliased as #format): Returns the string resulting from applying
|
|
152
|
+
# the given format string to any additional arguments.
|
|
153
|
+
# * #syscall: Runs an operating system call.
|
|
154
|
+
# * #trap: Specifies the handling of system signals.
|
|
155
|
+
# * #warn: Issue a warning based on the given messages and options.
|
|
275
156
|
#
|
|
276
157
|
%a{annotate:rdoc:source:from=object.c}
|
|
277
158
|
module Kernel : BasicObject
|
|
@@ -508,21 +389,19 @@ module Kernel : BasicObject
|
|
|
508
389
|
|
|
509
390
|
# <!--
|
|
510
391
|
# rdoc-file=object.c
|
|
511
|
-
# - Array(
|
|
392
|
+
# - Array(object) -> object or new_array
|
|
512
393
|
# -->
|
|
513
|
-
# Returns
|
|
394
|
+
# Returns an array converted from `object`.
|
|
395
|
+
#
|
|
396
|
+
# Tries to convert `object` to an array using `to_ary` first and `to_a` second:
|
|
514
397
|
#
|
|
515
|
-
#
|
|
516
|
-
#
|
|
398
|
+
# Array([0, 1, 2]) # => [0, 1, 2]
|
|
399
|
+
# Array({foo: 0, bar: 1}) # => [[:foo, 0], [:bar, 1]]
|
|
400
|
+
# Array(0..4) # => [0, 1, 2, 3, 4]
|
|
517
401
|
#
|
|
518
|
-
#
|
|
519
|
-
# TypeError.
|
|
402
|
+
# Returns `object` in an array, `[object]`, if `object` cannot be converted:
|
|
520
403
|
#
|
|
521
|
-
# Array(
|
|
522
|
-
# Array(1..5) #=> [1, 2, 3, 4, 5]
|
|
523
|
-
# Array(key: :value) #=> [[:key, :value]]
|
|
524
|
-
# Array(nil) #=> []
|
|
525
|
-
# Array(1) #=> [1]
|
|
404
|
+
# Array(:foo) # => [:foo]
|
|
526
405
|
#
|
|
527
406
|
def self?.Array: (NilClass x) -> [ ]
|
|
528
407
|
| [T] (::Array[T] x) -> ::Array[T]
|
|
@@ -589,46 +468,111 @@ module Kernel : BasicObject
|
|
|
589
468
|
|
|
590
469
|
# <!--
|
|
591
470
|
# rdoc-file=object.c
|
|
592
|
-
# - Hash(
|
|
471
|
+
# - Hash(object) -> object or new_hash
|
|
593
472
|
# -->
|
|
594
|
-
#
|
|
595
|
-
#
|
|
473
|
+
# Returns a hash converted from `object`.
|
|
474
|
+
#
|
|
475
|
+
# * If `object` is:
|
|
476
|
+
#
|
|
477
|
+
# * A hash, returns `object`.
|
|
478
|
+
# * An empty array or `nil`, returns an empty hash.
|
|
479
|
+
#
|
|
596
480
|
#
|
|
597
|
-
#
|
|
598
|
-
#
|
|
599
|
-
#
|
|
600
|
-
#
|
|
481
|
+
# * Otherwise, if `object.to_hash` returns a hash, returns that hash.
|
|
482
|
+
# * Otherwise, returns TypeError.
|
|
483
|
+
#
|
|
484
|
+
#
|
|
485
|
+
# Examples:
|
|
486
|
+
#
|
|
487
|
+
# Hash({foo: 0, bar: 1}) # => {:foo=>0, :bar=>1}
|
|
488
|
+
# Hash(nil) # => {}
|
|
489
|
+
# Hash([]) # => {}
|
|
601
490
|
#
|
|
602
491
|
def self?.Hash: [K, V] (Object x) -> ::Hash[K, V]
|
|
603
492
|
|
|
604
493
|
# <!--
|
|
605
494
|
# rdoc-file=object.c
|
|
606
|
-
# - Integer(
|
|
495
|
+
# - Integer(object, base = 0, exception: true) -> integer or nil
|
|
607
496
|
# -->
|
|
608
|
-
#
|
|
609
|
-
#
|
|
610
|
-
#
|
|
611
|
-
#
|
|
612
|
-
#
|
|
613
|
-
#
|
|
614
|
-
#
|
|
615
|
-
#
|
|
616
|
-
#
|
|
617
|
-
#
|
|
618
|
-
#
|
|
619
|
-
#
|
|
620
|
-
#
|
|
621
|
-
#
|
|
622
|
-
#
|
|
623
|
-
#
|
|
624
|
-
#
|
|
625
|
-
# Integer(
|
|
626
|
-
# Integer(
|
|
627
|
-
#
|
|
628
|
-
#
|
|
629
|
-
#
|
|
630
|
-
#
|
|
631
|
-
#
|
|
497
|
+
# Returns an integer converted from `object`.
|
|
498
|
+
#
|
|
499
|
+
# Tries to convert `object` to an integer using `to_int` first and `to_i`
|
|
500
|
+
# second; see below for exceptions.
|
|
501
|
+
#
|
|
502
|
+
# With a non-zero `base`, `object` must be a string or convertible to a string.
|
|
503
|
+
#
|
|
504
|
+
# #### numeric objects
|
|
505
|
+
#
|
|
506
|
+
# With integer argument `object` given, returns `object`:
|
|
507
|
+
#
|
|
508
|
+
# Integer(1) # => 1
|
|
509
|
+
# Integer(-1) # => -1
|
|
510
|
+
#
|
|
511
|
+
# With floating-point argument `object` given, returns `object` truncated to an
|
|
512
|
+
# intger:
|
|
513
|
+
#
|
|
514
|
+
# Integer(1.9) # => 1 # Rounds toward zero.
|
|
515
|
+
# Integer(-1.9) # => -1 # Rounds toward zero.
|
|
516
|
+
#
|
|
517
|
+
# #### string objects
|
|
518
|
+
#
|
|
519
|
+
# With string argument `object` and zero `base` given, returns `object`
|
|
520
|
+
# converted to an integer in base 10:
|
|
521
|
+
#
|
|
522
|
+
# Integer('100') # => 100
|
|
523
|
+
# Integer('-100') # => -100
|
|
524
|
+
#
|
|
525
|
+
# With `base` zero, string `object` may contain leading characters to specify
|
|
526
|
+
# the actual base (radix indicator):
|
|
527
|
+
#
|
|
528
|
+
# Integer('0100') # => 64 # Leading '0' specifies base 8.
|
|
529
|
+
# Integer('0b100') # => 4 # Leading '0b', specifies base 2.
|
|
530
|
+
# Integer('0x100') # => 256 # Leading '0x' specifies base 16.
|
|
531
|
+
#
|
|
532
|
+
# With a positive `base` (in range 2..36) given, returns `object` converted to
|
|
533
|
+
# an integer in the given base:
|
|
534
|
+
#
|
|
535
|
+
# Integer('100', 2) # => 4
|
|
536
|
+
# Integer('100', 8) # => 64
|
|
537
|
+
# Integer('-100', 16) # => -256
|
|
538
|
+
#
|
|
539
|
+
# With a negative `base` (in range -36..-2) given, returns `object` converted to
|
|
540
|
+
# an integer in the radix indicator if exists or `-base`:
|
|
541
|
+
#
|
|
542
|
+
# Integer('0x100', -2) # => 256
|
|
543
|
+
# Integer('100', -2) # => 4
|
|
544
|
+
# Integer('0b100', -8) # => 4
|
|
545
|
+
# Integer('100', -8) # => 64
|
|
546
|
+
# Integer('0o100', -10) # => 64
|
|
547
|
+
# Integer('100', -10) # => 100
|
|
548
|
+
#
|
|
549
|
+
# `base` -1 is equal the -10 case.
|
|
550
|
+
#
|
|
551
|
+
# When converting strings, surrounding whitespace and embedded underscores are
|
|
552
|
+
# allowed and ignored:
|
|
553
|
+
#
|
|
554
|
+
# Integer(' 100 ') # => 100
|
|
555
|
+
# Integer('-1_0_0', 16) # => -256
|
|
556
|
+
#
|
|
557
|
+
# #### other classes
|
|
558
|
+
#
|
|
559
|
+
# Examples with `object` of various other classes:
|
|
560
|
+
#
|
|
561
|
+
# Integer(Rational(9, 10)) # => 0 # Rounds toward zero.
|
|
562
|
+
# Integer(Complex(2, 0)) # => 2 # Imaginary part must be zero.
|
|
563
|
+
# Integer(Time.now) # => 1650974042
|
|
564
|
+
#
|
|
565
|
+
# #### keywords
|
|
566
|
+
#
|
|
567
|
+
# With optional keyword argument `exception` given as `true` (the default):
|
|
568
|
+
#
|
|
569
|
+
# * Raises TypeError if `object` does not respond to `to_int` or `to_i`.
|
|
570
|
+
# * Raises TypeError if `object` is `nil`.
|
|
571
|
+
# * Raise ArgumentError if `object` is an invalid string.
|
|
572
|
+
#
|
|
573
|
+
#
|
|
574
|
+
# With `exception` given as `false`, an exception of any kind is suppressed and
|
|
575
|
+
# `nil` is returned.
|
|
632
576
|
#
|
|
633
577
|
def self?.Integer: (Numeric | String arg, ?exception: bool exception) -> Integer
|
|
634
578
|
| (String arg, ?Integer base, ?exception: bool exception) -> Integer
|
|
@@ -674,15 +618,17 @@ module Kernel : BasicObject
|
|
|
674
618
|
|
|
675
619
|
# <!--
|
|
676
620
|
# rdoc-file=object.c
|
|
677
|
-
# - String(
|
|
621
|
+
# - String(object) -> object or new_string
|
|
678
622
|
# -->
|
|
679
|
-
# Returns
|
|
623
|
+
# Returns a string converted from `object`.
|
|
624
|
+
#
|
|
625
|
+
# Tries to convert `object` to a string using `to_str` first and `to_s` second:
|
|
680
626
|
#
|
|
681
|
-
#
|
|
627
|
+
# String([0, 1, 2]) # => "[0, 1, 2]"
|
|
628
|
+
# String(0..5) # => "0..5"
|
|
629
|
+
# String({foo: 0, bar: 1}) # => "{:foo=>0, :bar=>1}"
|
|
682
630
|
#
|
|
683
|
-
#
|
|
684
|
-
# String(self.class) #=> "Object"
|
|
685
|
-
# String(123456) #=> "123456"
|
|
631
|
+
# Raises `TypeError` if `object` cannot be converted to a string.
|
|
686
632
|
#
|
|
687
633
|
def self?.String: (_ToStr | _ToS x) -> String
|
|
688
634
|
|
|
@@ -717,15 +663,22 @@ module Kernel : BasicObject
|
|
|
717
663
|
|
|
718
664
|
# <!--
|
|
719
665
|
# rdoc-file=io.c
|
|
720
|
-
# - `
|
|
666
|
+
# - `command` -> string
|
|
721
667
|
# -->
|
|
722
|
-
# Returns the
|
|
723
|
-
#
|
|
668
|
+
# Returns the `$stdout` output from running `command` in a subshell; sets global
|
|
669
|
+
# variable `$?` to the process status.
|
|
670
|
+
#
|
|
671
|
+
# This method has potential security vulnerabilities if called with untrusted
|
|
672
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
673
|
+
#
|
|
674
|
+
# Examples:
|
|
724
675
|
#
|
|
725
|
-
# `date`
|
|
726
|
-
# `
|
|
727
|
-
#
|
|
728
|
-
# $?.
|
|
676
|
+
# $ `date` # => "Wed Apr 9 08:56:30 CDT 2003\n"
|
|
677
|
+
# $ `echo oops && exit 99` # => "oops\n"
|
|
678
|
+
# $ $? # => #<Process::Status: pid 17088 exit 99>
|
|
679
|
+
# $ $?.status # => 99>
|
|
680
|
+
#
|
|
681
|
+
# The built-in syntax `%x{...}` uses this method.
|
|
729
682
|
#
|
|
730
683
|
def self?.`: (String arg0) -> String
|
|
731
684
|
|
|
@@ -763,12 +716,16 @@ module Kernel : BasicObject
|
|
|
763
716
|
|
|
764
717
|
# <!--
|
|
765
718
|
# rdoc-file=load.c
|
|
766
|
-
# - autoload(
|
|
719
|
+
# - autoload(const, filename) -> nil
|
|
767
720
|
# -->
|
|
768
|
-
# Registers
|
|
769
|
-
#
|
|
721
|
+
# Registers _filename_ to be loaded (using Kernel::require)
|
|
722
|
+
# the first time that _const_ (which may be a String or
|
|
723
|
+
# a symbol) is accessed.
|
|
724
|
+
#
|
|
725
|
+
# autoload(:MyModule, "/usr/local/lib/modules/my_module.rb")
|
|
770
726
|
#
|
|
771
|
-
#
|
|
727
|
+
# If *const* is defined as autoload, the file name to be loaded is replaced with
|
|
728
|
+
# *filename*. If *const* is defined but not as autoload, does nothing.
|
|
772
729
|
#
|
|
773
730
|
def self?.autoload: (String | Symbol _module, String filename) -> NilClass
|
|
774
731
|
|
|
@@ -905,512 +862,25 @@ module Kernel : BasicObject
|
|
|
905
862
|
alias self.raise self.fail
|
|
906
863
|
|
|
907
864
|
# <!-- rdoc-file=object.c -->
|
|
908
|
-
# Returns the string resulting from
|
|
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"
|
|
865
|
+
# Returns the string resulting from formatting `objects` into `format_string`.
|
|
1148
866
|
#
|
|
1149
|
-
# For
|
|
1150
|
-
#
|
|
867
|
+
# For details on `format_string`, see [Format
|
|
868
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
|
1151
869
|
#
|
|
1152
|
-
#
|
|
1153
|
-
# sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
|
|
1154
|
-
# #=> 1 : 2.000000
|
|
1155
|
-
# sprintf("%{foo}f", { :foo => 1 })
|
|
1156
|
-
# # => "1f"
|
|
870
|
+
# Kernel#format is an alias for Kernel#sprintf.
|
|
1157
871
|
#
|
|
1158
872
|
def self?.format: (String format, *untyped args) -> String
|
|
1159
873
|
|
|
1160
874
|
# <!--
|
|
1161
875
|
# rdoc-file=object.c
|
|
1162
|
-
# -
|
|
1163
|
-
# - sprintf(format_string [, arguments...] ) -> string
|
|
876
|
+
# - sprintf(format_string *objects) -> string
|
|
1164
877
|
# -->
|
|
1165
|
-
# Returns the string resulting from
|
|
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"
|
|
878
|
+
# Returns the string resulting from formatting `objects` into `format_string`.
|
|
1396
879
|
#
|
|
1397
|
-
#
|
|
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.
|
|
880
|
+
# For details on `format_string`, see [Format
|
|
881
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
|
1408
882
|
#
|
|
1409
|
-
#
|
|
1410
|
-
# sprintf("%<foo>d : %<bar>f", { :foo => 1, :bar => 2 })
|
|
1411
|
-
# #=> 1 : 2.000000
|
|
1412
|
-
# sprintf("%{foo}f", { :foo => 1 })
|
|
1413
|
-
# # => "1f"
|
|
883
|
+
# Kernel#format is an alias for Kernel#sprintf.
|
|
1414
884
|
#
|
|
1415
885
|
alias sprintf format
|
|
1416
886
|
|
|
@@ -1462,7 +932,7 @@ module Kernel : BasicObject
|
|
|
1462
932
|
|
|
1463
933
|
# <!--
|
|
1464
934
|
# rdoc-file=load.c
|
|
1465
|
-
# - load(
|
|
935
|
+
# - load(file, wrap = false)
|
|
1466
936
|
# -->
|
|
1467
937
|
# Loads and executes the Ruby program in the file *filename*.
|
|
1468
938
|
#
|
|
@@ -1501,7 +971,7 @@ module Kernel : BasicObject
|
|
|
1501
971
|
# loop do
|
|
1502
972
|
# print "Input: "
|
|
1503
973
|
# line = gets
|
|
1504
|
-
# break if !line or line =~ /^
|
|
974
|
+
# break if !line or line =~ /^q/i
|
|
1505
975
|
# # ...
|
|
1506
976
|
# end
|
|
1507
977
|
#
|
|
@@ -1523,134 +993,183 @@ module Kernel : BasicObject
|
|
|
1523
993
|
|
|
1524
994
|
# <!--
|
|
1525
995
|
# rdoc-file=io.c
|
|
1526
|
-
# - open(path
|
|
1527
|
-
# - open(path
|
|
996
|
+
# - open(path, mode = 'r', perm = 0666, **opts) -> io or nil
|
|
997
|
+
# - open(path, mode = 'r', perm = 0666, **opts) {|io| ... } -> obj
|
|
1528
998
|
# -->
|
|
1529
999
|
# Creates an IO object connected to the given stream, file, or subprocess.
|
|
1530
1000
|
#
|
|
1531
|
-
#
|
|
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.
|
|
1001
|
+
# Required string argument `path` determines which of the following occurs:
|
|
1540
1002
|
#
|
|
1541
|
-
#
|
|
1542
|
-
#
|
|
1543
|
-
#
|
|
1003
|
+
# * The file at the specified `path` is opened.
|
|
1004
|
+
# * The process forks.
|
|
1005
|
+
# * A subprocess is created.
|
|
1544
1006
|
#
|
|
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
1007
|
#
|
|
1549
|
-
#
|
|
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.
|
|
1008
|
+
# Each of these is detailed below.
|
|
1553
1009
|
#
|
|
1554
|
-
#
|
|
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.
|
|
1010
|
+
# **File Opened**
|
|
1558
1011
|
#
|
|
1559
|
-
#
|
|
1560
|
-
#
|
|
1561
|
-
# --- once in the parent and once in the child.
|
|
1012
|
+
# If `path` does *not* start with a pipe character (`'|'`), a file stream is
|
|
1013
|
+
# opened with `File.open(path, mode, perm, **opts)`.
|
|
1562
1014
|
#
|
|
1563
|
-
#
|
|
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.
|
|
1015
|
+
# With no block given, file stream is returned:
|
|
1566
1016
|
#
|
|
1567
|
-
#
|
|
1017
|
+
# open('t.txt') # => #<File:t.txt>
|
|
1568
1018
|
#
|
|
1569
|
-
#
|
|
1019
|
+
# With a block given, calls the block with the open file stream, then closes the
|
|
1020
|
+
# stream:
|
|
1570
1021
|
#
|
|
1571
|
-
# open(
|
|
1572
|
-
# print f.gets
|
|
1573
|
-
# end
|
|
1574
|
-
#
|
|
1575
|
-
# Produces:
|
|
1022
|
+
# open('t.txt') {|f| p f } # => #<File:t.txt (closed)>
|
|
1576
1023
|
#
|
|
1577
|
-
#
|
|
1024
|
+
# Output:
|
|
1578
1025
|
#
|
|
1579
|
-
#
|
|
1026
|
+
# #<File:t.txt>
|
|
1580
1027
|
#
|
|
1581
|
-
#
|
|
1582
|
-
# print cmd.gets
|
|
1583
|
-
# cmd.close
|
|
1028
|
+
# See File.open for details.
|
|
1584
1029
|
#
|
|
1585
|
-
#
|
|
1030
|
+
# **Process Forked**
|
|
1586
1031
|
#
|
|
1587
|
-
#
|
|
1032
|
+
# If `path` is the 2-character string `'|-'`, the process forks and the child
|
|
1033
|
+
# process is connected to the parent.
|
|
1588
1034
|
#
|
|
1589
|
-
#
|
|
1035
|
+
# With no block given:
|
|
1590
1036
|
#
|
|
1591
|
-
#
|
|
1592
|
-
# if
|
|
1593
|
-
# puts "
|
|
1594
|
-
# exit
|
|
1037
|
+
# io = open('|-')
|
|
1038
|
+
# if io
|
|
1039
|
+
# $stderr.puts "In parent, child pid is #{io.pid}."
|
|
1595
1040
|
# else
|
|
1596
|
-
# puts "
|
|
1041
|
+
# $stderr.puts "In child, pid is #{$$}."
|
|
1597
1042
|
# end
|
|
1598
1043
|
#
|
|
1599
|
-
#
|
|
1044
|
+
# Output:
|
|
1600
1045
|
#
|
|
1601
|
-
#
|
|
1046
|
+
# In parent, child pid is 27903.
|
|
1047
|
+
# In child, pid is 27903.
|
|
1602
1048
|
#
|
|
1603
|
-
#
|
|
1049
|
+
# With a block given:
|
|
1604
1050
|
#
|
|
1605
|
-
# open
|
|
1606
|
-
# if
|
|
1607
|
-
#
|
|
1608
|
-
# puts "Got: #{f.gets}"
|
|
1051
|
+
# open('|-') do |io|
|
|
1052
|
+
# if io
|
|
1053
|
+
# $stderr.puts "In parent, child pid is #{io.pid}."
|
|
1609
1054
|
# else
|
|
1610
|
-
#
|
|
1611
|
-
# puts "in Child"
|
|
1055
|
+
# $stderr.puts "In child, pid is #{$$}."
|
|
1612
1056
|
# end
|
|
1613
1057
|
# end
|
|
1614
1058
|
#
|
|
1615
|
-
#
|
|
1059
|
+
# Output:
|
|
1060
|
+
#
|
|
1061
|
+
# In parent, child pid is 28427.
|
|
1062
|
+
# In child, pid is 28427.
|
|
1063
|
+
#
|
|
1064
|
+
# **Subprocess Created**
|
|
1065
|
+
#
|
|
1066
|
+
# If `path` is `'|command'` (`'command' != '-'`), a new subprocess runs the
|
|
1067
|
+
# command; its open stream is returned. Note that the command may be processed
|
|
1068
|
+
# by shell if it contains shell metacharacters.
|
|
1069
|
+
#
|
|
1070
|
+
# With no block given:
|
|
1071
|
+
#
|
|
1072
|
+
# io = open('|echo "Hi!"') # => #<IO:fd 12>
|
|
1073
|
+
# print io.gets
|
|
1074
|
+
# io.close
|
|
1075
|
+
#
|
|
1076
|
+
# Output:
|
|
1077
|
+
#
|
|
1078
|
+
# "Hi!"
|
|
1079
|
+
#
|
|
1080
|
+
# With a block given, calls the block with the stream, then closes the stream:
|
|
1081
|
+
#
|
|
1082
|
+
# open('|echo "Hi!"') do |io|
|
|
1083
|
+
# print io.gets
|
|
1084
|
+
# end
|
|
1085
|
+
#
|
|
1086
|
+
# Output:
|
|
1616
1087
|
#
|
|
1617
|
-
#
|
|
1088
|
+
# "Hi!"
|
|
1618
1089
|
#
|
|
1619
1090
|
def self?.open: (String name, ?String mode, ?Integer perm) -> IO?
|
|
1620
1091
|
| [T] (String name, ?String mode, ?Integer perm) { (IO) -> T } -> T
|
|
1621
1092
|
|
|
1622
1093
|
# <!--
|
|
1623
1094
|
# rdoc-file=io.c
|
|
1624
|
-
# - print(
|
|
1095
|
+
# - print(*objects) -> nil
|
|
1625
1096
|
# -->
|
|
1626
|
-
#
|
|
1627
|
-
#
|
|
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.
|
|
1097
|
+
# Equivalent to `$stdout.print(*objects)`, this method is the straightforward
|
|
1098
|
+
# way to write to `$stdout`.
|
|
1631
1099
|
#
|
|
1632
|
-
#
|
|
1633
|
-
#
|
|
1634
|
-
#
|
|
1635
|
-
#
|
|
1100
|
+
# Writes the given objects to `$stdout`; returns `nil`. Appends the output
|
|
1101
|
+
# record separator `$OUTPUT_RECORD_SEPARATOR` `$\`), if it is not `nil`.
|
|
1102
|
+
#
|
|
1103
|
+
# With argument `objects` given, for each object:
|
|
1104
|
+
#
|
|
1105
|
+
# * Converts via its method `to_s` if not a string.
|
|
1106
|
+
# * Writes to `stdout`.
|
|
1107
|
+
# * If not the last object, writes the output field separator
|
|
1108
|
+
# `$OUTPUT_FIELD_SEPARATOR` (`$,` if it is not `nil`.
|
|
1636
1109
|
#
|
|
1637
|
-
# *produces:*
|
|
1638
1110
|
#
|
|
1639
|
-
#
|
|
1640
|
-
#
|
|
1111
|
+
# With default separators:
|
|
1112
|
+
#
|
|
1113
|
+
# objects = [0, 0.0, Rational(0, 1), Complex(0, 0), :zero, 'zero']
|
|
1114
|
+
# $OUTPUT_RECORD_SEPARATOR
|
|
1115
|
+
# $OUTPUT_FIELD_SEPARATOR
|
|
1116
|
+
# print(*objects)
|
|
1117
|
+
#
|
|
1118
|
+
# Output:
|
|
1119
|
+
#
|
|
1120
|
+
# nil
|
|
1121
|
+
# nil
|
|
1122
|
+
# 00.00/10+0izerozero
|
|
1123
|
+
#
|
|
1124
|
+
# With specified separators:
|
|
1125
|
+
#
|
|
1126
|
+
# $OUTPUT_RECORD_SEPARATOR = "\n"
|
|
1127
|
+
# $OUTPUT_FIELD_SEPARATOR = ','
|
|
1128
|
+
# print(*objects)
|
|
1129
|
+
#
|
|
1130
|
+
# Output:
|
|
1131
|
+
#
|
|
1132
|
+
# 0,0.0,0/1,0+0i,zero,zero
|
|
1133
|
+
#
|
|
1134
|
+
# With no argument given, writes the content of `$_` (which is usually the most
|
|
1135
|
+
# recent user input):
|
|
1136
|
+
#
|
|
1137
|
+
# gets # Sets $_ to the most recent user input.
|
|
1138
|
+
# print # Prints $_.
|
|
1641
1139
|
#
|
|
1642
1140
|
def self?.print: (*Kernel args) -> nil
|
|
1643
1141
|
|
|
1644
1142
|
# <!--
|
|
1645
1143
|
# rdoc-file=io.c
|
|
1646
|
-
# - printf(
|
|
1647
|
-
# - printf(
|
|
1144
|
+
# - printf(format_string, *objects) -> nil
|
|
1145
|
+
# - printf(io, format_string, *objects) -> nil
|
|
1648
1146
|
# -->
|
|
1649
1147
|
# Equivalent to:
|
|
1650
|
-
# io.write(sprintf(string, obj, ...))
|
|
1651
1148
|
#
|
|
1652
|
-
#
|
|
1653
|
-
#
|
|
1149
|
+
# io.write(sprintf(format_string, *objects))
|
|
1150
|
+
#
|
|
1151
|
+
# For details on `format_string`, see [Format
|
|
1152
|
+
# Specifications](rdoc-ref:format_specifications.rdoc).
|
|
1153
|
+
#
|
|
1154
|
+
# With the single argument `format_string`, formats `objects` into the string,
|
|
1155
|
+
# then writes the formatted string to $stdout:
|
|
1156
|
+
#
|
|
1157
|
+
# printf('%4.4d %10s %2.2f', 24, 24, 24.0)
|
|
1158
|
+
#
|
|
1159
|
+
# Output (on $stdout):
|
|
1160
|
+
#
|
|
1161
|
+
# 0024 24 24.00#
|
|
1162
|
+
#
|
|
1163
|
+
# With arguments `io` and `format_string`, formats `objects` into the string,
|
|
1164
|
+
# then writes the formatted string to `io`:
|
|
1165
|
+
#
|
|
1166
|
+
# printf($stderr, '%4.4d %10s %2.2f', 24, 24, 24.0)
|
|
1167
|
+
#
|
|
1168
|
+
# Output (on $stderr):
|
|
1169
|
+
#
|
|
1170
|
+
# 0024 24 24.00# => nil
|
|
1171
|
+
#
|
|
1172
|
+
# With no arguments, does nothing.
|
|
1654
1173
|
#
|
|
1655
1174
|
def self?.printf: (IO arg0, String arg1, *untyped args) -> nil
|
|
1656
1175
|
| (String arg1, *untyped args) -> nil
|
|
@@ -1675,44 +1194,51 @@ module Kernel : BasicObject
|
|
|
1675
1194
|
|
|
1676
1195
|
# <!--
|
|
1677
1196
|
# rdoc-file=io.c
|
|
1678
|
-
# - putc(int)
|
|
1197
|
+
# - putc(int) -> int
|
|
1679
1198
|
# -->
|
|
1680
1199
|
# Equivalent to:
|
|
1681
1200
|
#
|
|
1682
1201
|
# $stdout.putc(int)
|
|
1683
1202
|
#
|
|
1684
|
-
#
|
|
1685
|
-
# multi-byte characters.
|
|
1203
|
+
# See IO#putc for important information regarding multi-byte characters.
|
|
1686
1204
|
#
|
|
1687
1205
|
def self?.putc: (Integer arg0) -> Integer
|
|
1688
1206
|
| (String arg0) -> String
|
|
1689
1207
|
|
|
1690
1208
|
# <!--
|
|
1691
1209
|
# rdoc-file=io.c
|
|
1692
|
-
# - puts(
|
|
1210
|
+
# - puts(*objects) -> nil
|
|
1693
1211
|
# -->
|
|
1694
1212
|
# Equivalent to
|
|
1695
1213
|
#
|
|
1696
|
-
# $stdout.puts(
|
|
1214
|
+
# $stdout.puts(objects)
|
|
1697
1215
|
#
|
|
1698
1216
|
def self?.puts: (*untyped arg0) -> NilClass
|
|
1699
1217
|
|
|
1700
1218
|
# <!--
|
|
1701
1219
|
# rdoc-file=io.c
|
|
1702
|
-
# - p(
|
|
1703
|
-
# - p(
|
|
1704
|
-
# - p
|
|
1220
|
+
# - p(object) -> obj
|
|
1221
|
+
# - p(*objects) -> array of objects
|
|
1222
|
+
# - p -> nil
|
|
1705
1223
|
# -->
|
|
1706
|
-
# For each object
|
|
1707
|
-
# program's standard output.
|
|
1224
|
+
# For each object `obj`, executes:
|
|
1708
1225
|
#
|
|
1709
|
-
#
|
|
1710
|
-
# s = S['dave', 'TX']
|
|
1711
|
-
# p s
|
|
1226
|
+
# $stdout.write(obj.inspect, "\n")
|
|
1712
1227
|
#
|
|
1713
|
-
#
|
|
1228
|
+
# With one object given, returns the object; with multiple objects given,
|
|
1229
|
+
# returns an array containing the objects; with no object given, returns `nil`.
|
|
1230
|
+
#
|
|
1231
|
+
# Examples:
|
|
1232
|
+
#
|
|
1233
|
+
# r = Range.new(0, 4)
|
|
1234
|
+
# p r # => 0..4
|
|
1235
|
+
# p [r, r, r] # => [0..4, 0..4, 0..4]
|
|
1236
|
+
# p # => nil
|
|
1237
|
+
#
|
|
1238
|
+
# Output:
|
|
1714
1239
|
#
|
|
1715
|
-
#
|
|
1240
|
+
# 0..4
|
|
1241
|
+
# [0..4, 0..4, 0..4]
|
|
1716
1242
|
#
|
|
1717
1243
|
def self?.p: [T] (T arg0) -> T
|
|
1718
1244
|
| (*untyped arg0) -> Array[untyped]
|
|
@@ -1744,7 +1270,7 @@ module Kernel : BasicObject
|
|
|
1744
1270
|
# rand(100) #=> 12
|
|
1745
1271
|
#
|
|
1746
1272
|
# When `max` is a Range, `rand` returns a random number where
|
|
1747
|
-
# range.member?(number) == true
|
|
1273
|
+
# `range.member?(number) == true`.
|
|
1748
1274
|
#
|
|
1749
1275
|
# Negative or floating point values for `max` are allowed, but may give
|
|
1750
1276
|
# surprising results.
|
|
@@ -1765,92 +1291,142 @@ module Kernel : BasicObject
|
|
|
1765
1291
|
|
|
1766
1292
|
# <!--
|
|
1767
1293
|
# rdoc-file=io.c
|
|
1768
|
-
# - readline(sep
|
|
1769
|
-
# - readline(limit) -> string
|
|
1770
|
-
# - readline(sep, limit) -> string
|
|
1294
|
+
# - readline(sep = $/, chomp: false) -> string
|
|
1295
|
+
# - readline(limit, chomp: false) -> string
|
|
1296
|
+
# - readline(sep, limit, chomp: false) -> string
|
|
1771
1297
|
# -->
|
|
1772
|
-
# Equivalent to Kernel
|
|
1773
|
-
#
|
|
1298
|
+
# Equivalent to method Kernel#gets, except that it raises an exception if called
|
|
1299
|
+
# at end-of-stream:
|
|
1300
|
+
#
|
|
1301
|
+
# $ cat t.txt | ruby -e "p readlines; readline"
|
|
1302
|
+
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
|
1303
|
+
# in `readline': end of file reached (EOFError)
|
|
1304
|
+
#
|
|
1305
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
|
1306
|
+
# omitted.
|
|
1774
1307
|
#
|
|
1775
1308
|
def self?.readline: (?String arg0, ?Integer arg1) -> String
|
|
1776
1309
|
|
|
1777
1310
|
# <!--
|
|
1778
1311
|
# rdoc-file=io.c
|
|
1779
|
-
# - readlines(sep
|
|
1780
|
-
# - readlines(limit)
|
|
1781
|
-
# - readlines(sep, limit) -> array
|
|
1312
|
+
# - readlines(sep = $/, chomp: false, **enc_opts) -> array
|
|
1313
|
+
# - readlines(limit, chomp: false, **enc_opts) -> array
|
|
1314
|
+
# - readlines(sep, limit, chomp: false, **enc_opts) -> array
|
|
1782
1315
|
# -->
|
|
1783
|
-
# Returns an array containing the lines returned by calling
|
|
1784
|
-
#
|
|
1316
|
+
# Returns an array containing the lines returned by calling Kernel#gets until
|
|
1317
|
+
# the end-of-stream is reached; (see [Line IO](rdoc-ref:IO@Line+IO)).
|
|
1318
|
+
#
|
|
1319
|
+
# With only string argument `sep` given, returns the remaining lines as
|
|
1320
|
+
# determined by line separator `sep`, or `nil` if none; see [Line
|
|
1321
|
+
# Separator](rdoc-ref:IO@Line+Separator):
|
|
1322
|
+
#
|
|
1323
|
+
# # Default separator.
|
|
1324
|
+
# $ cat t.txt | ruby -e "p readlines"
|
|
1325
|
+
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
|
1326
|
+
#
|
|
1327
|
+
# # Specified separator.
|
|
1328
|
+
# $ cat t.txt | ruby -e "p readlines 'li'"
|
|
1329
|
+
# ["First li", "ne\nSecond li", "ne\n\nFourth li", "ne\nFifth li", "ne\n"]
|
|
1330
|
+
#
|
|
1331
|
+
# # Get-all separator.
|
|
1332
|
+
# $ cat t.txt | ruby -e "p readlines nil"
|
|
1333
|
+
# ["First line\nSecond line\n\nFourth line\nFifth line\n"]
|
|
1334
|
+
#
|
|
1335
|
+
# # Get-paragraph separator.
|
|
1336
|
+
# $ cat t.txt | ruby -e "p readlines ''"
|
|
1337
|
+
# ["First line\nSecond line\n\n", "Fourth line\nFifth line\n"]
|
|
1338
|
+
#
|
|
1339
|
+
# With only integer argument `limit` given, limits the number of bytes in the
|
|
1340
|
+
# line; see [Line Limit](rdoc-ref:IO@Line+Limit):
|
|
1341
|
+
#
|
|
1342
|
+
# $cat t.txt | ruby -e "p readlines 10"
|
|
1343
|
+
# ["First line", "\n", "Second lin", "e\n", "\n", "Fourth lin", "e\n", "Fifth line", "\n"]
|
|
1344
|
+
#
|
|
1345
|
+
# $cat t.txt | ruby -e "p readlines 11"
|
|
1346
|
+
# ["First line\n", "Second line", "\n", "\n", "Fourth line", "\n", "Fifth line\n"]
|
|
1347
|
+
#
|
|
1348
|
+
# $cat t.txt | ruby -e "p readlines 12"
|
|
1349
|
+
# ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
|
1350
|
+
#
|
|
1351
|
+
# With arguments `sep` and `limit` given, combines the two behaviors; see [Line
|
|
1352
|
+
# Separator and Line Limit](rdoc-ref:IO@Line+Separator+and+Line+Limit).
|
|
1353
|
+
#
|
|
1354
|
+
# Optional keyword argument `chomp` specifies whether line separators are to be
|
|
1355
|
+
# omitted:
|
|
1356
|
+
#
|
|
1357
|
+
# $ cat t.txt | ruby -e "p readlines(chomp: true)"
|
|
1358
|
+
# ["First line", "Second line", "", "Fourth line", "Fifth line"]
|
|
1359
|
+
#
|
|
1360
|
+
# Optional keyword arguments `enc_opts` specify encoding options; see [Encoding
|
|
1361
|
+
# options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
|
1785
1362
|
#
|
|
1786
1363
|
def self?.readlines: (?String arg0, ?Integer arg1) -> ::Array[String]
|
|
1787
1364
|
|
|
1788
1365
|
# <!--
|
|
1789
|
-
# rdoc-file=
|
|
1790
|
-
# - require(
|
|
1366
|
+
# rdoc-file=lib/rubygems/core_ext/kernel_require.rb
|
|
1367
|
+
# - require(path)
|
|
1791
1368
|
# -->
|
|
1792
|
-
#
|
|
1793
|
-
#
|
|
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.
|
|
1369
|
+
# When RubyGems is required, Kernel#require is replaced with our own which is
|
|
1370
|
+
# capable of loading gems on demand.
|
|
1805
1371
|
#
|
|
1806
|
-
#
|
|
1807
|
-
#
|
|
1808
|
-
#
|
|
1372
|
+
# When you call `require 'x'`, this is what happens:
|
|
1373
|
+
# * If the file can be loaded from the existing Ruby loadpath, it is.
|
|
1374
|
+
# * Otherwise, installed gems are searched for a file that matches. If it's
|
|
1375
|
+
# found in gem 'y', that gem is activated (added to the loadpath).
|
|
1809
1376
|
#
|
|
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
1377
|
#
|
|
1814
|
-
#
|
|
1815
|
-
#
|
|
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.
|
|
1378
|
+
# The normal `require` functionality of returning false if that file has already
|
|
1379
|
+
# been loaded is preserved.
|
|
1820
1380
|
#
|
|
1821
1381
|
def self?.require: (String path) -> bool
|
|
1822
1382
|
|
|
1823
1383
|
# <!--
|
|
1824
1384
|
# rdoc-file=load.c
|
|
1825
|
-
# - require_relative(
|
|
1385
|
+
# - require_relative(file)
|
|
1826
1386
|
# -->
|
|
1827
|
-
# Ruby tries to load the library named *string* relative to the
|
|
1828
|
-
#
|
|
1829
|
-
#
|
|
1387
|
+
# Ruby tries to load the library named *string* relative to the directory
|
|
1388
|
+
# containing the requiring file. If the file does not exist a LoadError is
|
|
1389
|
+
# raised. Returns `true` if the file was loaded and `false` if the file was
|
|
1390
|
+
# already loaded before.
|
|
1830
1391
|
#
|
|
1831
1392
|
def self?.require_relative: (String feature) -> bool
|
|
1832
1393
|
|
|
1833
1394
|
# <!--
|
|
1834
1395
|
# rdoc-file=io.c
|
|
1835
|
-
# - IO.select(
|
|
1396
|
+
# - IO.select(read_ios, write_ios = [], error_ios = [], timeout = nil) -> array or nil
|
|
1836
1397
|
# -->
|
|
1837
|
-
#
|
|
1838
|
-
# until one or more of
|
|
1839
|
-
#
|
|
1840
|
-
#
|
|
1841
|
-
#
|
|
1398
|
+
# Invokes system call [select(2)](https://linux.die.net/man/2/select), which
|
|
1399
|
+
# monitors multiple file descriptors, waiting until one or more of the file
|
|
1400
|
+
# descriptors becomes ready for some class of I/O operation.
|
|
1401
|
+
#
|
|
1402
|
+
# Not implemented on all platforms.
|
|
1403
|
+
#
|
|
1404
|
+
# Each of the arguments `read_ios`, `write_ios`, and `error_ios` is an array of
|
|
1405
|
+
# IO objects.
|
|
1406
|
+
#
|
|
1407
|
+
# Argument `timeout` is an integer timeout interval in seconds.
|
|
1408
|
+
#
|
|
1409
|
+
# The method monitors the IO objects given in all three arrays, waiting for some
|
|
1410
|
+
# to be ready; returns a 3-element array whose elements are:
|
|
1411
|
+
#
|
|
1412
|
+
# * An array of the objects in `read_ios` that are ready for reading.
|
|
1413
|
+
# * An array of the objects in `write_ios` that are ready for writing.
|
|
1414
|
+
# * An array of the objects in `error_ios` have pending exceptions.
|
|
1415
|
+
#
|
|
1416
|
+
#
|
|
1417
|
+
# If no object becomes ready within the given `timeout`, `nil` is returned.
|
|
1842
1418
|
#
|
|
1843
1419
|
# IO.select peeks the buffer of IO objects for testing readability. If the IO
|
|
1844
1420
|
# buffer is not empty, IO.select immediately notifies readability. This "peek"
|
|
1845
1421
|
# only happens for IO objects. It does not happen for IO-like objects such as
|
|
1846
1422
|
# OpenSSL::SSL::SSLSocket.
|
|
1847
1423
|
#
|
|
1848
|
-
# The best way to use IO.select is invoking it after
|
|
1849
|
-
# #read_nonblock, #write_nonblock, etc. The methods raise an exception which
|
|
1850
|
-
# extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
|
|
1851
|
-
# caller should wait with IO.select. If IO::WaitReadable is raised, the
|
|
1852
|
-
# should wait for reading. If IO::WaitWritable is raised, the caller
|
|
1853
|
-
# wait for writing.
|
|
1424
|
+
# The best way to use IO.select is invoking it after non-blocking methods such
|
|
1425
|
+
# as #read_nonblock, #write_nonblock, etc. The methods raise an exception which
|
|
1426
|
+
# is extended by IO::WaitReadable or IO::WaitWritable. The modules notify how
|
|
1427
|
+
# the caller should wait with IO.select. If IO::WaitReadable is raised, the
|
|
1428
|
+
# caller should wait for reading. If IO::WaitWritable is raised, the caller
|
|
1429
|
+
# should wait for writing.
|
|
1854
1430
|
#
|
|
1855
1431
|
# So, blocking read (#readpartial) can be emulated using #read_nonblock and
|
|
1856
1432
|
# IO.select as follows:
|
|
@@ -1865,7 +1441,7 @@ module Kernel : BasicObject
|
|
|
1865
1441
|
# retry
|
|
1866
1442
|
# end
|
|
1867
1443
|
#
|
|
1868
|
-
# Especially, the combination of
|
|
1444
|
+
# Especially, the combination of non-blocking methods and IO.select is preferred
|
|
1869
1445
|
# for IO like objects such as OpenSSL::SSL::SSLSocket. It has #to_io method to
|
|
1870
1446
|
# return underlying IO object. IO.select calls #to_io to obtain the file
|
|
1871
1447
|
# descriptor to wait.
|
|
@@ -1891,13 +1467,13 @@ module Kernel : BasicObject
|
|
|
1891
1467
|
# blocking. So, the caller should wait for ready for writability as above
|
|
1892
1468
|
# example.
|
|
1893
1469
|
#
|
|
1894
|
-
# The combination of
|
|
1470
|
+
# The combination of non-blocking methods and IO.select is also useful for
|
|
1895
1471
|
# streams such as tty, pipe socket socket when multiple processes read from a
|
|
1896
1472
|
# stream.
|
|
1897
1473
|
#
|
|
1898
1474
|
# Finally, Linux kernel developers don't guarantee that readability of select(2)
|
|
1899
|
-
# means readability of following read(2) even for a single process
|
|
1900
|
-
# select(2)
|
|
1475
|
+
# means readability of following read(2) even for a single process; see
|
|
1476
|
+
# [select(2)](https://linux.die.net/man/2/select)
|
|
1901
1477
|
#
|
|
1902
1478
|
# Invoking IO.select before IO#readpartial works well as usual. However it is
|
|
1903
1479
|
# not the best way to use IO.select.
|
|
@@ -1924,18 +1500,7 @@ module Kernel : BasicObject
|
|
|
1924
1500
|
# string = string.byteslice(written..-1)
|
|
1925
1501
|
# end
|
|
1926
1502
|
#
|
|
1927
|
-
#
|
|
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
|
|
1503
|
+
# Example:
|
|
1939
1504
|
#
|
|
1940
1505
|
# rp, wp = IO.pipe
|
|
1941
1506
|
# mesg = "ping "
|
|
@@ -1957,7 +1522,7 @@ module Kernel : BasicObject
|
|
|
1957
1522
|
# end
|
|
1958
1523
|
# }
|
|
1959
1524
|
#
|
|
1960
|
-
#
|
|
1525
|
+
# Output:
|
|
1961
1526
|
#
|
|
1962
1527
|
# ping pong
|
|
1963
1528
|
# ping pong
|
|
@@ -1992,31 +1557,27 @@ module Kernel : BasicObject
|
|
|
1992
1557
|
|
|
1993
1558
|
# <!--
|
|
1994
1559
|
# rdoc-file=io.c
|
|
1995
|
-
# - syscall(
|
|
1560
|
+
# - syscall(integer_callno, *arguments) -> integer
|
|
1996
1561
|
# -->
|
|
1997
|
-
#
|
|
1998
|
-
#
|
|
1562
|
+
# Invokes Posix system call [syscall(2)](https://linux.die.net/man/2/syscall),
|
|
1563
|
+
# which calls a specified function.
|
|
1999
1564
|
#
|
|
2000
|
-
#
|
|
2001
|
-
#
|
|
2002
|
-
#
|
|
2003
|
-
#
|
|
1565
|
+
# Calls the operating system function identified by `integer_callno`; returns
|
|
1566
|
+
# the result of the function or raises SystemCallError if it failed. The effect
|
|
1567
|
+
# of the call is platform-dependent. The arguments and returned value are
|
|
1568
|
+
# platform-dependent.
|
|
2004
1569
|
#
|
|
2005
|
-
#
|
|
2006
|
-
#
|
|
1570
|
+
# For each of `arguments`: if it is an integer, it is passed directly; if it is
|
|
1571
|
+
# a string, it is interpreted as a binary sequence of bytes. There may be as
|
|
1572
|
+
# many as nine such arguments.
|
|
2007
1573
|
#
|
|
2008
|
-
#
|
|
1574
|
+
# Arguments `integer_callno` and `argument`, as well as the returned value, are
|
|
1575
|
+
# platform-dependent.
|
|
2009
1576
|
#
|
|
2010
|
-
#
|
|
1577
|
+
# Note: Method `syscall` is essentially unsafe and unportable. The DL (Fiddle)
|
|
1578
|
+
# library is preferred for safer and a bit more portable programming.
|
|
2011
1579
|
#
|
|
2012
|
-
#
|
|
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.
|
|
1580
|
+
# Not implemented on all platforms.
|
|
2020
1581
|
#
|
|
2021
1582
|
def self?.syscall: (Integer num, *untyped args) -> untyped
|
|
2022
1583
|
|
|
@@ -2037,8 +1598,7 @@ module Kernel : BasicObject
|
|
|
2037
1598
|
# "d" | boolean | True if file1 exists and is a directory
|
|
2038
1599
|
# "e" | boolean | True if file1 exists
|
|
2039
1600
|
# "f" | boolean | True if file1 exists and is a regular file
|
|
2040
|
-
# "g" | boolean | True if file1 has the
|
|
2041
|
-
# | | set (false under NT)
|
|
1601
|
+
# "g" | boolean | True if file1 has the setgid bit set
|
|
2042
1602
|
# "G" | boolean | True if file1 exists and has a group
|
|
2043
1603
|
# | | ownership equal to the caller's group
|
|
2044
1604
|
# "k" | boolean | True if file1 exists and has the sticky bit set
|
|
@@ -2149,7 +1709,7 @@ module Kernel : BasicObject
|
|
|
2149
1709
|
# `exec(cmdname, arg1, ...)`
|
|
2150
1710
|
# : command name and one or more arguments (no shell)
|
|
2151
1711
|
# `exec([cmdname, argv0], arg1, ...)`
|
|
2152
|
-
# : command name, [
|
|
1712
|
+
# : command name, `argv[0]` and zero or more arguments (no shell)
|
|
2153
1713
|
#
|
|
2154
1714
|
#
|
|
2155
1715
|
# In the first form, the string is taken as a command line that is subject to
|
|
@@ -2163,11 +1723,12 @@ module Kernel : BasicObject
|
|
|
2163
1723
|
# If the string from the first form (`exec("command")`) follows these simple
|
|
2164
1724
|
# rules:
|
|
2165
1725
|
#
|
|
2166
|
-
# * no meta characters
|
|
2167
|
-
# * not starting with shell reserved word or special built-in
|
|
2168
|
-
# * Ruby invokes the command directly without shell
|
|
1726
|
+
# * no meta characters,
|
|
1727
|
+
# * not starting with shell reserved word or special built-in,
|
|
2169
1728
|
#
|
|
2170
1729
|
#
|
|
1730
|
+
# Ruby invokes the command directly without shell.
|
|
1731
|
+
#
|
|
2171
1732
|
# You can force shell invocation by adding ";" to the string (because ";" is a
|
|
2172
1733
|
# meta character).
|
|
2173
1734
|
#
|
|
@@ -2469,6 +2030,9 @@ module Kernel : BasicObject
|
|
|
2469
2030
|
# -->
|
|
2470
2031
|
# Executes *command...* in a subshell. *command...* is one of following forms.
|
|
2471
2032
|
#
|
|
2033
|
+
# This method has potential security vulnerabilities if called with untrusted
|
|
2034
|
+
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2035
|
+
#
|
|
2472
2036
|
# `commandline`
|
|
2473
2037
|
# : command line string which is passed to the standard shell
|
|
2474
2038
|
# `cmdname, arg1, ...`
|