rbs 4.0.0.dev.4 → 4.1.0.pre.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/.clang-format +1 -0
- data/.github/dependabot.yml +16 -14
- data/.github/workflows/bundle-update.yml +63 -0
- data/.github/workflows/c-check.yml +21 -11
- data/.github/workflows/comments.yml +5 -3
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/jruby.yml +67 -0
- data/.github/workflows/milestone.yml +83 -0
- data/.github/workflows/ruby.yml +63 -24
- data/.github/workflows/rust.yml +184 -0
- data/.github/workflows/truffleruby.yml +54 -0
- data/.github/workflows/typecheck.yml +5 -2
- data/.github/workflows/wasm.yml +53 -0
- data/.github/workflows/windows.yml +8 -2
- data/.gitignore +11 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +357 -0
- data/README.md +4 -4
- data/Rakefile +365 -33
- data/Steepfile +8 -0
- data/config.yml +450 -24
- data/core/array.rbs +443 -363
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +9 -8
- data/core/class.rbs +11 -8
- data/core/comparable.rbs +55 -34
- data/core/complex.rbs +104 -78
- data/core/dir.rbs +61 -49
- data/core/encoding.rbs +12 -15
- data/core/enumerable.rbs +288 -196
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator/product.rbs +5 -5
- data/core/enumerator.rbs +91 -28
- data/core/errno.rbs +11 -2
- data/core/errors.rbs +58 -29
- data/core/exception.rbs +13 -13
- data/core/fiber.rbs +74 -54
- data/core/file.rbs +260 -1151
- data/core/file_constants.rbs +463 -0
- data/core/file_stat.rbs +534 -0
- data/core/file_test.rbs +3 -3
- data/core/float.rbs +257 -92
- data/core/gc.rbs +425 -281
- data/core/hash.rbs +1151 -829
- data/core/integer.rbs +156 -195
- data/core/io/buffer.rbs +53 -42
- data/core/io/wait.rbs +13 -35
- data/core/io.rbs +216 -150
- data/core/kernel.rbs +239 -163
- data/core/marshal.rbs +4 -4
- data/core/match_data.rbs +15 -13
- data/core/math.rbs +107 -66
- data/core/method.rbs +69 -33
- data/core/module.rbs +302 -150
- data/core/nil_class.rbs +7 -6
- data/core/numeric.rbs +77 -63
- data/core/object.rbs +9 -11
- data/core/object_space/weak_key_map.rbs +7 -7
- data/core/object_space.rbs +30 -23
- data/core/pathname.rbs +1322 -0
- data/core/proc.rbs +95 -58
- data/core/process.rbs +222 -202
- data/core/ractor.rbs +371 -515
- data/core/random.rbs +21 -3
- data/core/range.rbs +181 -79
- data/core/rational.rbs +60 -89
- data/core/rbs/ops.rbs +154 -0
- data/core/rbs/unnamed/argf.rbs +63 -56
- data/core/rbs/unnamed/env_class.rbs +19 -14
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +11 -118
- data/core/regexp.rbs +258 -214
- data/core/ruby.rbs +53 -0
- data/core/ruby_vm.rbs +78 -34
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +4 -71
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +16 -82
- data/core/rubygems/version.rbs +2 -3
- data/core/set.rbs +493 -363
- data/core/signal.rbs +26 -16
- data/core/string.rbs +3234 -1285
- data/core/struct.rbs +43 -42
- data/core/symbol.rbs +41 -34
- data/core/thread.rbs +141 -73
- data/core/time.rbs +81 -50
- data/core/trace_point.rbs +41 -35
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +24 -16
- data/core/warning.rbs +7 -7
- data/docs/CONTRIBUTING.md +2 -1
- data/docs/aliases.md +79 -0
- data/docs/collection.md +3 -3
- data/docs/config.md +171 -0
- data/docs/encoding.md +56 -0
- data/docs/gem.md +0 -1
- data/docs/inline.md +634 -0
- data/docs/rbs_by_example.md +20 -20
- data/docs/rust.md +96 -0
- data/docs/sigs.md +3 -3
- data/docs/syntax.md +48 -18
- data/docs/type_fingerprint.md +21 -0
- data/docs/wasm_serialization.md +80 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +1441 -671
- data/ext/rbs_extension/ast_translation.h +7 -0
- data/ext/rbs_extension/class_constants.c +18 -2
- data/ext/rbs_extension/class_constants.h +9 -0
- data/ext/rbs_extension/extconf.rb +6 -1
- data/ext/rbs_extension/legacy_location.c +33 -56
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +183 -39
- data/include/rbs/ast.h +597 -297
- data/include/rbs/defines.h +40 -0
- data/include/rbs/lexer.h +31 -11
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +6 -6
- data/include/rbs/serialize.h +39 -0
- data/include/rbs/string.h +0 -2
- data/include/rbs/util/rbs_allocator.h +34 -13
- data/include/rbs/util/rbs_assert.h +12 -1
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs/util/rbs_encoding.h +2 -0
- data/include/rbs/util/rbs_unescape.h +2 -1
- data/include/rbs.h +8 -0
- data/lib/rbs/annotate/rdoc_annotator.rb +27 -31
- data/lib/rbs/ast/annotation.rb +1 -1
- data/lib/rbs/ast/comment.rb +1 -1
- data/lib/rbs/ast/declarations.rb +10 -10
- data/lib/rbs/ast/members.rb +14 -14
- data/lib/rbs/ast/ruby/annotations.rb +335 -3
- data/lib/rbs/ast/ruby/comment_block.rb +30 -4
- data/lib/rbs/ast/ruby/declarations.rb +209 -4
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +4 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +1 -1
- data/lib/rbs/ast/ruby/members.rb +571 -22
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +66 -24
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +38 -106
- data/lib/rbs/cli.rb +55 -24
- data/lib/rbs/collection/config/lockfile_generator.rb +28 -3
- data/lib/rbs/collection/sources/git.rb +7 -0
- data/lib/rbs/definition.rb +1 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +62 -9
- data/lib/rbs/definition_builder/method_builder.rb +32 -6
- data/lib/rbs/definition_builder.rb +147 -25
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment.rb +235 -75
- data/lib/rbs/environment_loader.rb +0 -6
- data/lib/rbs/errors.rb +27 -18
- data/lib/rbs/inline_parser.rb +377 -15
- data/lib/rbs/location_aux.rb +1 -1
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +47 -11
- data/lib/rbs/parser_aux.rb +20 -7
- data/lib/rbs/prototype/helpers.rb +57 -0
- data/lib/rbs/prototype/rb.rb +3 -28
- data/lib/rbs/prototype/rbi.rb +3 -20
- data/lib/rbs/prototype/runtime.rb +10 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +120 -44
- data/lib/rbs/rewriter.rb +70 -0
- data/lib/rbs/subtractor.rb +3 -1
- data/lib/rbs/test/type_check.rb +25 -3
- data/lib/rbs/type_name.rb +34 -14
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/type_assertions.rb +44 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs/wasm/deserializer.rb +213 -0
- data/lib/rbs/wasm/location.rb +61 -0
- data/lib/rbs/wasm/parser.rb +137 -0
- data/lib/rbs/wasm/runtime.rb +217 -0
- data/lib/rbs/wasm/serialization_schema.rb +110 -0
- data/lib/rbs.rb +13 -2
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +1 -1
- data/rbs.gemspec +24 -6
- data/schema/typeParam.json +17 -1
- data/sig/annotate/rdoc_annotater.rbs +12 -9
- data/sig/ast/ruby/annotations.rbs +364 -4
- data/sig/ast/ruby/comment_block.rbs +8 -0
- data/sig/ast/ruby/declarations.rbs +102 -4
- data/sig/ast/ruby/members.rbs +128 -2
- data/sig/buffer.rbs +19 -1
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/collection/config/lockfile_generator.rbs +2 -0
- data/sig/definition.rbs +6 -1
- data/sig/definition_builder.rbs +2 -0
- data/sig/environment.rbs +70 -12
- data/sig/errors.rbs +13 -14
- data/sig/inline_parser.rbs +41 -2
- data/sig/locator.rbs +0 -2
- data/sig/manifest.yaml +0 -2
- data/sig/method_builder.rbs +3 -1
- data/sig/namespace.rbs +20 -0
- data/sig/parser.rbs +41 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +36 -10
- data/sig/rewriter.rbs +45 -0
- data/sig/source.rbs +3 -3
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +15 -0
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +15 -0
- data/sig/wasm/deserializer.rbs +66 -0
- data/sig/wasm/serialization_schema.rbs +13 -0
- data/src/ast.c +443 -162
- data/src/lexer.c +1415 -1313
- data/src/lexer.re +4 -0
- data/src/lexstate.c +63 -37
- data/src/location.c +7 -47
- data/src/parser.c +1032 -521
- data/src/serialize.c +958 -0
- data/src/string.c +0 -48
- data/src/util/rbs_allocator.c +89 -74
- data/src/util/rbs_assert.c +1 -1
- data/src/util/rbs_buffer.c +2 -2
- data/src/util/rbs_constant_pool.c +10 -14
- data/src/util/rbs_encoding.c +4 -8
- data/src/util/rbs_unescape.c +56 -20
- data/stdlib/abbrev/0/array.rbs +1 -1
- data/stdlib/bigdecimal/0/big_decimal.rbs +116 -98
- data/stdlib/bigdecimal-math/0/big_math.rbs +169 -8
- data/stdlib/cgi/0/core.rbs +9 -393
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +171 -0
- data/stdlib/coverage/0/coverage.rbs +7 -4
- data/stdlib/csv/0/csv.rbs +5 -5
- data/stdlib/date/0/date.rbs +92 -79
- data/stdlib/date/0/date_time.rbs +25 -24
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +111 -1
- data/stdlib/erb/0/erb.rbs +748 -347
- data/stdlib/etc/0/etc.rbs +73 -54
- data/stdlib/fileutils/0/fileutils.rbs +179 -160
- data/stdlib/forwardable/0/forwardable.rbs +13 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +223 -142
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +162 -134
- data/stdlib/objspace/0/objspace.rbs +17 -34
- data/stdlib/open-uri/0/open-uri.rbs +48 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +482 -364
- data/stdlib/optparse/0/optparse.rbs +26 -17
- data/stdlib/pathname/0/pathname.rbs +11 -1381
- data/stdlib/pp/0/pp.rbs +9 -8
- data/stdlib/prettyprint/0/prettyprint.rbs +7 -7
- data/stdlib/pstore/0/pstore.rbs +35 -30
- data/stdlib/psych/0/psych.rbs +65 -12
- data/stdlib/psych/0/store.rbs +2 -4
- data/stdlib/pty/0/pty.rbs +9 -6
- data/stdlib/random-formatter/0/random-formatter.rbs +277 -0
- data/stdlib/rdoc/0/code_object.rbs +2 -1
- data/stdlib/rdoc/0/parser.rbs +1 -1
- data/stdlib/rdoc/0/rdoc.rbs +1 -1
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +26 -69
- data/stdlib/ripper/0/ripper.rbs +22 -19
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +3 -3
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/addrinfo.rbs +7 -7
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +23 -10
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +11 -3
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +1209 -95
- data/stdlib/strscan/0/string_scanner.rbs +101 -80
- data/stdlib/tempfile/0/tempfile.rbs +25 -21
- data/stdlib/time/0/time.rbs +8 -6
- data/stdlib/timeout/0/timeout.rbs +63 -7
- data/stdlib/tsort/0/cyclic.rbs +4 -1
- data/stdlib/tsort/0/interfaces.rbs +8 -8
- data/stdlib/tsort/0/tsort.rbs +16 -15
- data/stdlib/uri/0/common.rbs +42 -20
- data/stdlib/uri/0/file.rbs +3 -3
- data/stdlib/uri/0/generic.rbs +26 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/ldap.rbs +2 -2
- data/stdlib/uri/0/mailto.rbs +3 -3
- data/stdlib/uri/0/rfc2396_parser.rbs +12 -12
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +8 -8
- data/stdlib/zlib/0/gzip_writer.rbs +14 -12
- data/stdlib/zlib/0/inflate.rbs +1 -1
- data/stdlib/zlib/0/need_dict.rbs +1 -1
- data/stdlib/zlib/0/zstream.rbs +1 -0
- data/wasm/README.md +59 -0
- data/wasm/rbs_wasm.c +411 -0
- metadata +56 -8
- data/.vscode/extensions.json +0 -5
- data/.vscode/settings.json +0 -19
data/core/io.rbs
CHANGED
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
# classes in the Ruby standard library are also subclasses of IO; these include
|
|
8
8
|
# TCPSocket and UDPSocket.
|
|
9
9
|
#
|
|
10
|
-
# The global constant ARGF (also accessible as
|
|
11
|
-
# that allows access to all file paths found in ARGV (or found in
|
|
12
|
-
# is empty). ARGF is not itself a subclass of IO.
|
|
10
|
+
# The global constant ARGF (also accessible as <code>$<</code>) provides an
|
|
11
|
+
# IO-like stream that allows access to all file paths found in ARGV (or found in
|
|
12
|
+
# STDIN if ARGV is empty). ARGF is not itself a subclass of IO.
|
|
13
13
|
#
|
|
14
14
|
# Class StringIO provides an IO-like stream that handles a String. StringIO is
|
|
15
15
|
# not itself a subclass of IO.
|
|
@@ -46,10 +46,10 @@
|
|
|
46
46
|
# from the position mentioned above); see [Line
|
|
47
47
|
# Number](rdoc-ref:IO@Line+Number).
|
|
48
48
|
#
|
|
49
|
-
# ## Extension
|
|
49
|
+
# ## Extension <code>io/console</code>
|
|
50
50
|
#
|
|
51
|
-
# Extension
|
|
52
|
-
# console; requiring it adds numerous methods to class IO.
|
|
51
|
+
# Extension <code>io/console</code> provides numerous methods for interacting
|
|
52
|
+
# with the console; requiring it adds numerous methods to class IO.
|
|
53
53
|
#
|
|
54
54
|
# ## Example Files
|
|
55
55
|
#
|
|
@@ -86,23 +86,23 @@
|
|
|
86
86
|
# A number of IO methods accept optional keyword arguments that determine how a
|
|
87
87
|
# new stream is to be opened:
|
|
88
88
|
#
|
|
89
|
-
# *
|
|
90
|
-
# *
|
|
91
|
-
# bitwise-ORed.
|
|
92
|
-
# *
|
|
93
|
-
# *
|
|
94
|
-
# for the default internal encoding. If the
|
|
95
|
-
# occurs.
|
|
96
|
-
# *
|
|
97
|
-
#
|
|
98
|
-
# *
|
|
99
|
-
# otherwise.
|
|
100
|
-
# *
|
|
101
|
-
# otherwise.
|
|
102
|
-
# *
|
|
103
|
-
# the stream closes; otherwise it remains open.
|
|
104
|
-
# *
|
|
105
|
-
# available as #path method.
|
|
89
|
+
# * <code>:mode</code>: Stream mode.
|
|
90
|
+
# * <code>:flags</code>: Integer file open flags; If `mode` is also given, the
|
|
91
|
+
# two are bitwise-ORed.
|
|
92
|
+
# * <code>:external_encoding</code>: External encoding for the stream.
|
|
93
|
+
# * <code>:internal_encoding</code>: Internal encoding for the stream.
|
|
94
|
+
# <code>'-'</code> is a synonym for the default internal encoding. If the
|
|
95
|
+
# value is `nil` no conversion occurs.
|
|
96
|
+
# * <code>:encoding</code>: Specifies external and internal encodings as
|
|
97
|
+
# <code>'extern:intern'</code>.
|
|
98
|
+
# * <code>:textmode</code>: If a truthy value, specifies the mode as
|
|
99
|
+
# text-only, binary otherwise.
|
|
100
|
+
# * <code>:binmode</code>: If a truthy value, specifies the mode as binary,
|
|
101
|
+
# text-only otherwise.
|
|
102
|
+
# * <code>:autoclose</code>: If a truthy value, specifies that the `fd` will
|
|
103
|
+
# close when the stream closes; otherwise it remains open.
|
|
104
|
+
# * <code>:path:</code> If a string value is provided, it is used in #inspect
|
|
105
|
+
# and is available as #path method.
|
|
106
106
|
#
|
|
107
107
|
# Also available are the options offered in String#encode, which may control
|
|
108
108
|
# conversion between external and internal encoding.
|
|
@@ -129,8 +129,8 @@
|
|
|
129
129
|
#
|
|
130
130
|
# The relevant methods:
|
|
131
131
|
#
|
|
132
|
-
# * IO#tell (aliased as
|
|
133
|
-
# the stream.
|
|
132
|
+
# * IO#tell (aliased as <code>#pos</code>): Returns the current position (in
|
|
133
|
+
# bytes) in the stream.
|
|
134
134
|
# * IO#pos=: Sets the position of the stream to a given integer `new_position`
|
|
135
135
|
# (in bytes).
|
|
136
136
|
# * IO#seek: Sets the position of the stream to a given integer `offset` (in
|
|
@@ -158,8 +158,8 @@
|
|
|
158
158
|
#
|
|
159
159
|
# You can query whether a stream is positioned at its end:
|
|
160
160
|
#
|
|
161
|
-
# * IO#eof? (also aliased as
|
|
162
|
-
# end-of-stream.
|
|
161
|
+
# * IO#eof? (also aliased as <code>#eof</code>): Returns whether the stream is
|
|
162
|
+
# at end-of-stream.
|
|
163
163
|
#
|
|
164
164
|
# You can reposition to end-of-stream by using method IO#seek:
|
|
165
165
|
#
|
|
@@ -225,8 +225,8 @@
|
|
|
225
225
|
# separator*: the string that determines what is considered a line; it is
|
|
226
226
|
# sometimes called the *input record separator*.
|
|
227
227
|
#
|
|
228
|
-
# The default line separator is taken from global variable
|
|
229
|
-
# value is
|
|
228
|
+
# The default line separator is taken from global variable <code>$/</code>,
|
|
229
|
+
# whose initial value is <code>"\n"</code>.
|
|
230
230
|
#
|
|
231
231
|
# Generally, the line to be read next is all data from the current
|
|
232
232
|
# [position](rdoc-ref:IO@Position) to the next line separator (but see [Special
|
|
@@ -250,7 +250,7 @@
|
|
|
250
250
|
# f.gets # => "e\n"
|
|
251
251
|
# f.close
|
|
252
252
|
#
|
|
253
|
-
# Or by setting global variable
|
|
253
|
+
# Or by setting global variable <code>$/</code>:
|
|
254
254
|
#
|
|
255
255
|
# f = File.new('t.txt')
|
|
256
256
|
# $/ = 'l'
|
|
@@ -270,8 +270,8 @@
|
|
|
270
270
|
# f.gets(nil) # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
271
271
|
# f.close
|
|
272
272
|
#
|
|
273
|
-
# *
|
|
274
|
-
# being separated by two consecutive line separators):
|
|
273
|
+
# * <code>''</code> (the empty string): The next "paragraph" is to be read
|
|
274
|
+
# (paragraphs being separated by two consecutive line separators):
|
|
275
275
|
#
|
|
276
276
|
# f = File.new('t.txt')
|
|
277
277
|
# f.gets('') # => "First line\nSecond line\n\n"
|
|
@@ -285,8 +285,8 @@
|
|
|
285
285
|
# multi-byte character will not be split, and so a returned line may be slightly
|
|
286
286
|
# longer than the limit).
|
|
287
287
|
#
|
|
288
|
-
# The default limit value is
|
|
289
|
-
# no limit.
|
|
288
|
+
# The default limit value is <code>-1</code>; any negative limit value means
|
|
289
|
+
# that there is no limit.
|
|
290
290
|
#
|
|
291
291
|
# If there is no limit, the line is determined only by `sep`.
|
|
292
292
|
#
|
|
@@ -385,10 +385,10 @@
|
|
|
385
385
|
# f.lineno # => 1001
|
|
386
386
|
# f.close
|
|
387
387
|
#
|
|
388
|
-
# Associated with the line number is the global variable
|
|
388
|
+
# Associated with the line number is the global variable <code>$.</code>:
|
|
389
389
|
#
|
|
390
|
-
# * When a stream is opened,
|
|
391
|
-
# previous activity in the process:
|
|
390
|
+
# * When a stream is opened, <code>$.</code> is not set; its value is left
|
|
391
|
+
# over from previous activity in the process:
|
|
392
392
|
#
|
|
393
393
|
# $. = 41
|
|
394
394
|
# f = File.new('t.txt')
|
|
@@ -396,7 +396,8 @@
|
|
|
396
396
|
# # => 41
|
|
397
397
|
# f.close
|
|
398
398
|
#
|
|
399
|
-
# * When a stream is read,
|
|
399
|
+
# * When a stream is read, <code>$.</code> is set to the line number for that
|
|
400
|
+
# stream:
|
|
400
401
|
#
|
|
401
402
|
# f0 = File.new('t.txt')
|
|
402
403
|
# f1 = File.new('t.dat')
|
|
@@ -407,7 +408,7 @@
|
|
|
407
408
|
# f0.close
|
|
408
409
|
# f1.close
|
|
409
410
|
#
|
|
410
|
-
# * Methods IO#rewind and IO#seek do not affect
|
|
411
|
+
# * Methods IO#rewind and IO#seek do not affect <code>$.</code>:
|
|
411
412
|
#
|
|
412
413
|
# f = File.new('t.txt')
|
|
413
414
|
# f.readlines # => ["First line\n", "Second line\n", "\n", "Fourth line\n", "Fifth line\n"]
|
|
@@ -652,15 +653,17 @@ class IO < Object
|
|
|
652
653
|
#
|
|
653
654
|
# Argument `advice` is one of the following symbols:
|
|
654
655
|
#
|
|
655
|
-
# *
|
|
656
|
-
# for the specified data. If no advice is given for an open
|
|
657
|
-
# the default assumption.
|
|
658
|
-
# *
|
|
659
|
-
# sequentially (with lower offsets read before higher ones).
|
|
660
|
-
# *
|
|
661
|
-
# *
|
|
662
|
-
# *
|
|
663
|
-
#
|
|
656
|
+
# * <code>:normal</code>: The application has no advice to give about its
|
|
657
|
+
# access pattern for the specified data. If no advice is given for an open
|
|
658
|
+
# file, this is the default assumption.
|
|
659
|
+
# * <code>:sequential</code>: The application expects to access the specified
|
|
660
|
+
# data sequentially (with lower offsets read before higher ones).
|
|
661
|
+
# * <code>:random</code>: The specified data will be accessed in random order.
|
|
662
|
+
# * <code>:noreuse</code>: The specified data will be accessed only once.
|
|
663
|
+
# * <code>:willneed</code>: The specified data will be accessed in the near
|
|
664
|
+
# future.
|
|
665
|
+
# * <code>:dontneed</code>: The specified data will not be accessed in the
|
|
666
|
+
# near future.
|
|
664
667
|
#
|
|
665
668
|
# Not implemented on all platforms.
|
|
666
669
|
#
|
|
@@ -724,8 +727,8 @@ class IO < Object
|
|
|
724
727
|
# If the stream is open for writing, flushes any buffered writes to the
|
|
725
728
|
# operating system before closing.
|
|
726
729
|
#
|
|
727
|
-
# If the stream was opened by IO.popen, sets global variable
|
|
728
|
-
# status).
|
|
730
|
+
# If the stream was opened by IO.popen, sets global variable <code>$?</code>
|
|
731
|
+
# (child exit status).
|
|
729
732
|
#
|
|
730
733
|
# It is not an error to close an IO object that has already been closed. It just
|
|
731
734
|
# returns nil.
|
|
@@ -790,7 +793,7 @@ class IO < Object
|
|
|
790
793
|
# and Closed Streams](rdoc-ref:IO@Open+and+Closed+Streams).
|
|
791
794
|
#
|
|
792
795
|
# If the stream was opened by IO.popen and is also closed for writing, sets
|
|
793
|
-
# global variable
|
|
796
|
+
# global variable <code>$?</code> (child exit status).
|
|
794
797
|
#
|
|
795
798
|
# Example:
|
|
796
799
|
#
|
|
@@ -824,7 +827,7 @@ class IO < Object
|
|
|
824
827
|
# Flushes any buffered writes to the operating system before closing.
|
|
825
828
|
#
|
|
826
829
|
# If the stream was opened by IO.popen and is also closed for reading, sets
|
|
827
|
-
# global variable
|
|
830
|
+
# global variable <code>$?</code> (child exit status).
|
|
828
831
|
#
|
|
829
832
|
# IO.popen('ruby', 'r+') do |pipe|
|
|
830
833
|
# puts pipe.closed?
|
|
@@ -990,8 +993,8 @@ class IO < Object
|
|
|
990
993
|
# - fdatasync -> 0
|
|
991
994
|
# -->
|
|
992
995
|
# Immediately writes to disk all data buffered in the stream, via the operating
|
|
993
|
-
# system's:
|
|
994
|
-
# supported; otherwise raises an exception.
|
|
996
|
+
# system's: <code>fdatasync(2)</code>, if supported, otherwise via
|
|
997
|
+
# <code>fsync(2)</code>, if supported; otherwise raises an exception.
|
|
995
998
|
#
|
|
996
999
|
def fdatasync: () -> Integer?
|
|
997
1000
|
|
|
@@ -1026,7 +1029,7 @@ class IO < Object
|
|
|
1026
1029
|
# - fsync -> 0
|
|
1027
1030
|
# -->
|
|
1028
1031
|
# Immediately writes to disk all data buffered in the stream, via the operating
|
|
1029
|
-
# system's
|
|
1032
|
+
# system's <code>fsync(2)</code>.
|
|
1030
1033
|
#
|
|
1031
1034
|
# Note this difference:
|
|
1032
1035
|
#
|
|
@@ -1036,7 +1039,8 @@ class IO < Object
|
|
|
1036
1039
|
# * IO#fsync: Ensures both that data is flushed from internal buffers, and
|
|
1037
1040
|
# that data is written to disk.
|
|
1038
1041
|
#
|
|
1039
|
-
# Raises an exception if the operating system does not support
|
|
1042
|
+
# Raises an exception if the operating system does not support
|
|
1043
|
+
# <code>fsync(2)</code>.
|
|
1040
1044
|
#
|
|
1041
1045
|
def fsync: () -> Integer?
|
|
1042
1046
|
|
|
@@ -1082,11 +1086,11 @@ class IO < Object
|
|
|
1082
1086
|
# - gets(limit, chomp: false) -> string or nil
|
|
1083
1087
|
# - gets(sep, limit, chomp: false) -> string or nil
|
|
1084
1088
|
# -->
|
|
1085
|
-
# Reads and returns a line from the stream; assigns the return value to
|
|
1086
|
-
# See [Line IO](rdoc-ref:IO@Line+IO).
|
|
1089
|
+
# Reads and returns a line from the stream; assigns the return value to
|
|
1090
|
+
# <code>$_</code>. See [Line IO](rdoc-ref:IO@Line+IO).
|
|
1087
1091
|
#
|
|
1088
1092
|
# With no arguments given, returns the next line as determined by line separator
|
|
1089
|
-
#
|
|
1093
|
+
# <code>$/</code>, or `nil` if none:
|
|
1090
1094
|
#
|
|
1091
1095
|
# f = File.open('t.txt')
|
|
1092
1096
|
# f.gets # => "First line\n"
|
|
@@ -1226,6 +1230,24 @@ class IO < Object
|
|
|
1226
1230
|
#
|
|
1227
1231
|
def ioctl: (Integer integer_cmd, String | Integer argument) -> Integer
|
|
1228
1232
|
|
|
1233
|
+
# <!--
|
|
1234
|
+
# rdoc-file=ext/etc/etc.c
|
|
1235
|
+
# - pathconf(name) -> Integer
|
|
1236
|
+
# -->
|
|
1237
|
+
# Returns pathname configuration variable using fpathconf().
|
|
1238
|
+
#
|
|
1239
|
+
# *name* should be a constant under `Etc` which begins with `PC_`.
|
|
1240
|
+
#
|
|
1241
|
+
# The return value is an integer or nil. nil means indefinite limit.
|
|
1242
|
+
# (fpathconf() returns -1 but errno is not set.)
|
|
1243
|
+
#
|
|
1244
|
+
# require 'etc'
|
|
1245
|
+
# IO.pipe {|r, w|
|
|
1246
|
+
# p w.pathconf(Etc::PC_PIPE_BUF) #=> 4096
|
|
1247
|
+
# }
|
|
1248
|
+
#
|
|
1249
|
+
def pathconf: (Integer name) -> Integer?
|
|
1250
|
+
|
|
1229
1251
|
# <!--
|
|
1230
1252
|
# rdoc-file=io.c
|
|
1231
1253
|
# - isatty -> true or false
|
|
@@ -1316,15 +1338,15 @@ class IO < Object
|
|
|
1316
1338
|
# - print(*objects) -> nil
|
|
1317
1339
|
# -->
|
|
1318
1340
|
# Writes the given objects to the stream; returns `nil`. Appends the output
|
|
1319
|
-
# record separator
|
|
1320
|
-
# [Line IO](rdoc-ref:IO@Line+IO).
|
|
1341
|
+
# record separator <code>$OUTPUT_RECORD_SEPARATOR</code> (<code>$\</code>), if
|
|
1342
|
+
# it is not `nil`. See [Line IO](rdoc-ref:IO@Line+IO).
|
|
1321
1343
|
#
|
|
1322
1344
|
# With argument `objects` given, for each object:
|
|
1323
1345
|
#
|
|
1324
1346
|
# * Converts via its method `to_s` if not a string.
|
|
1325
1347
|
# * Writes to the stream.
|
|
1326
1348
|
# * If not the last object, writes the output field separator
|
|
1327
|
-
#
|
|
1349
|
+
# <code>$OUTPUT_FIELD_SEPARATOR</code> (<code>$,</code>) if it is not `nil`.
|
|
1328
1350
|
#
|
|
1329
1351
|
# With default separators:
|
|
1330
1352
|
#
|
|
@@ -1356,8 +1378,8 @@ class IO < Object
|
|
|
1356
1378
|
#
|
|
1357
1379
|
# "0,0.0,0/1,0+0i,zero,zero\n"
|
|
1358
1380
|
#
|
|
1359
|
-
# With no argument given, writes the content of
|
|
1360
|
-
# recent user input):
|
|
1381
|
+
# With no argument given, writes the content of <code>$_</code> (which is
|
|
1382
|
+
# usually the most recent user input):
|
|
1361
1383
|
#
|
|
1362
1384
|
# f = File.open('t.tmp', 'w+')
|
|
1363
1385
|
# gets # Sets $_ to the most recent user input.
|
|
@@ -1373,7 +1395,7 @@ class IO < Object
|
|
|
1373
1395
|
# Formats and writes `objects` to the stream.
|
|
1374
1396
|
#
|
|
1375
1397
|
# For details on `format_string`, see [Format
|
|
1376
|
-
# Specifications](rdoc-ref:format_specifications.rdoc).
|
|
1398
|
+
# Specifications](rdoc-ref:language/format_specifications.rdoc).
|
|
1377
1399
|
#
|
|
1378
1400
|
def printf: (String format_string, *untyped objects) -> nil
|
|
1379
1401
|
|
|
@@ -1406,13 +1428,13 @@ class IO < Object
|
|
|
1406
1428
|
# newline sequence. If called without arguments, writes a newline. See [Line
|
|
1407
1429
|
# IO](rdoc-ref:IO@Line+IO).
|
|
1408
1430
|
#
|
|
1409
|
-
# Note that each added newline is the character
|
|
1410
|
-
# record separator (<tt
|
|
1431
|
+
# Note that each added newline is the character <code>"\n"<//tt>, not the output
|
|
1432
|
+
# record separator (<tt>$\</code>).
|
|
1411
1433
|
#
|
|
1412
1434
|
# Treatment for each object:
|
|
1413
1435
|
#
|
|
1414
1436
|
# * String: writes the string.
|
|
1415
|
-
# * Neither string nor array: writes
|
|
1437
|
+
# * Neither string nor array: writes <code>object.to_s</code>.
|
|
1416
1438
|
# * Array: writes each element of the array; arrays may be nested.
|
|
1417
1439
|
#
|
|
1418
1440
|
# To keep these examples brief, we define this helper method:
|
|
@@ -1443,6 +1465,61 @@ class IO < Object
|
|
|
1443
1465
|
#
|
|
1444
1466
|
def puts: (*untyped objects) -> nil
|
|
1445
1467
|
|
|
1468
|
+
# <!--
|
|
1469
|
+
# rdoc-file=io.c
|
|
1470
|
+
# - pread(maxlen, offset) -> string
|
|
1471
|
+
# - pread(maxlen, offset, out_string) -> string
|
|
1472
|
+
# -->
|
|
1473
|
+
# Behaves like IO#readpartial, except that it:
|
|
1474
|
+
#
|
|
1475
|
+
# * Reads at the given `offset` (in bytes).
|
|
1476
|
+
# * Disregards, and does not modify, the stream's position (see
|
|
1477
|
+
# [Position](rdoc-ref:IO@Position)).
|
|
1478
|
+
# * Bypasses any user space buffering in the stream.
|
|
1479
|
+
#
|
|
1480
|
+
# Because this method does not disturb the stream's state (its position, in
|
|
1481
|
+
# particular), `pread` allows multiple threads and processes to use the same IO
|
|
1482
|
+
# object for reading at various offsets.
|
|
1483
|
+
#
|
|
1484
|
+
# f = File.open('t.txt')
|
|
1485
|
+
# f.read # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
1486
|
+
# f.pos # => 52
|
|
1487
|
+
# # Read 12 bytes at offset 0.
|
|
1488
|
+
# f.pread(12, 0) # => "First line\n"
|
|
1489
|
+
# # Read 9 bytes at offset 8.
|
|
1490
|
+
# f.pread(9, 8) # => "ne\nSecon"
|
|
1491
|
+
# f.close
|
|
1492
|
+
#
|
|
1493
|
+
# Not available on some platforms.
|
|
1494
|
+
#
|
|
1495
|
+
def pread: (int maxlen, int offset, ?string? out_string) -> String
|
|
1496
|
+
|
|
1497
|
+
# <!--
|
|
1498
|
+
# rdoc-file=io.c
|
|
1499
|
+
# - pwrite(object, offset) -> integer
|
|
1500
|
+
# -->
|
|
1501
|
+
# Behaves like IO#write, except that it:
|
|
1502
|
+
#
|
|
1503
|
+
# * Writes at the given `offset` (in bytes).
|
|
1504
|
+
# * Disregards, and does not modify, the stream's position (see
|
|
1505
|
+
# [Position](rdoc-ref:IO@Position)).
|
|
1506
|
+
# * Bypasses any user space buffering in the stream.
|
|
1507
|
+
#
|
|
1508
|
+
# Because this method does not disturb the stream's state (its position, in
|
|
1509
|
+
# particular), `pwrite` allows multiple threads and processes to use the same IO
|
|
1510
|
+
# object for writing at various offsets.
|
|
1511
|
+
#
|
|
1512
|
+
# f = File.open('t.tmp', 'w+')
|
|
1513
|
+
# # Write 6 bytes at offset 3.
|
|
1514
|
+
# f.pwrite('ABCDEF', 3) # => 6
|
|
1515
|
+
# f.rewind
|
|
1516
|
+
# f.read # => "\u0000\u0000\u0000ABCDEF"
|
|
1517
|
+
# f.close
|
|
1518
|
+
#
|
|
1519
|
+
# Not available on some platforms.
|
|
1520
|
+
#
|
|
1521
|
+
def pwrite: (_ToS object, int offset) -> Integer
|
|
1522
|
+
|
|
1446
1523
|
# <!--
|
|
1447
1524
|
# rdoc-file=io.c
|
|
1448
1525
|
# - read(maxlen = nil, out_string = nil) -> new_string, out_string, or nil
|
|
@@ -1464,7 +1541,7 @@ class IO < Object
|
|
|
1464
1541
|
# * `out_string` given: encoding of `out_string` not modified.
|
|
1465
1542
|
# * `out_string` not given: ASCII-8BIT is used.
|
|
1466
1543
|
#
|
|
1467
|
-
#
|
|
1544
|
+
# <strong>Without Argument `out_string`</strong>
|
|
1468
1545
|
#
|
|
1469
1546
|
# When argument `out_string` is omitted, the returned value is a new string:
|
|
1470
1547
|
#
|
|
@@ -1479,7 +1556,7 @@ class IO < Object
|
|
|
1479
1556
|
#
|
|
1480
1557
|
# If `maxlen` is zero, returns an empty string.
|
|
1481
1558
|
#
|
|
1482
|
-
#
|
|
1559
|
+
# <strong> With Argument `out_string`</strong>
|
|
1483
1560
|
#
|
|
1484
1561
|
# When argument `out_string` is given, the returned value is `out_string`, whose
|
|
1485
1562
|
# content is replaced:
|
|
@@ -1512,8 +1589,8 @@ class IO < Object
|
|
|
1512
1589
|
#
|
|
1513
1590
|
# Related: IO#write.
|
|
1514
1591
|
#
|
|
1515
|
-
def read: (?nil, ?string outbuf) -> String
|
|
1516
|
-
| (int? length, ?string outbuf) -> String?
|
|
1592
|
+
def read: (?nil, ?string? outbuf) -> String
|
|
1593
|
+
| (int? length, ?string? outbuf) -> String?
|
|
1517
1594
|
|
|
1518
1595
|
# <!--
|
|
1519
1596
|
# rdoc-file=io.rb
|
|
@@ -1565,11 +1642,11 @@ class IO < Object
|
|
|
1565
1642
|
#
|
|
1566
1643
|
# By specifying a keyword argument *exception* to `false`, you can indicate that
|
|
1567
1644
|
# read_nonblock should not raise an IO::WaitReadable exception, but return the
|
|
1568
|
-
# symbol
|
|
1569
|
-
# EOFError.
|
|
1645
|
+
# symbol <code>:wait_readable</code> instead. At EOF, it will return nil instead
|
|
1646
|
+
# of raising EOFError.
|
|
1570
1647
|
#
|
|
1571
|
-
def read_nonblock: (int len, ?string buf, ?exception: true) -> String
|
|
1572
|
-
| (int len, ?string buf, exception: false) -> (String | :wait_readable | nil)
|
|
1648
|
+
def read_nonblock: (int len, ?string? buf, ?exception: true) -> String
|
|
1649
|
+
| (int len, ?string? buf, exception: false) -> (String | :wait_readable | nil)
|
|
1573
1650
|
|
|
1574
1651
|
# <!--
|
|
1575
1652
|
# rdoc-file=io.c
|
|
@@ -1626,11 +1703,11 @@ class IO < Object
|
|
|
1626
1703
|
# - readlines(limit, chomp: false) -> array
|
|
1627
1704
|
# - readlines(sep, limit, chomp: false) -> array
|
|
1628
1705
|
# -->
|
|
1629
|
-
# Reads and returns all remaining line from the stream; does not modify
|
|
1630
|
-
# See [Line IO](rdoc-ref:IO@Line+IO).
|
|
1706
|
+
# Reads and returns all remaining line from the stream; does not modify
|
|
1707
|
+
# <code>$_</code>. See [Line IO](rdoc-ref:IO@Line+IO).
|
|
1631
1708
|
#
|
|
1632
|
-
# With no arguments given, returns lines as determined by line separator
|
|
1633
|
-
# or `nil` if none:
|
|
1709
|
+
# With no arguments given, returns lines as determined by line separator
|
|
1710
|
+
# <code>$/</code>, or `nil` if none:
|
|
1634
1711
|
#
|
|
1635
1712
|
# f = File.new('t.txt')
|
|
1636
1713
|
# f.readlines
|
|
@@ -1769,7 +1846,7 @@ class IO < Object
|
|
|
1769
1846
|
# r.readpartial(4096) # => "def\n" "" "ghi\n"
|
|
1770
1847
|
# r.readpartial(4096) # => "ghi\n" "" ""
|
|
1771
1848
|
#
|
|
1772
|
-
def readpartial: (int maxlen, ?string outbuf) -> String
|
|
1849
|
+
def readpartial: (int maxlen, ?string? outbuf) -> String
|
|
1773
1850
|
|
|
1774
1851
|
# <!--
|
|
1775
1852
|
# rdoc-file=io.c
|
|
@@ -1836,8 +1913,8 @@ class IO < Object
|
|
|
1836
1913
|
# Seeks to the position given by integer `offset` (see
|
|
1837
1914
|
# [Position](rdoc-ref:IO@Position)) and constant `whence`, which is one of:
|
|
1838
1915
|
#
|
|
1839
|
-
# *
|
|
1840
|
-
# plus the given `offset`:
|
|
1916
|
+
# * <code>:CUR</code> or <code>IO::SEEK_CUR</code>: Repositions the stream to
|
|
1917
|
+
# its current position plus the given `offset`:
|
|
1841
1918
|
#
|
|
1842
1919
|
# f = File.open('t.txt')
|
|
1843
1920
|
# f.tell # => 0
|
|
@@ -1847,8 +1924,8 @@ class IO < Object
|
|
|
1847
1924
|
# f.tell # => 10
|
|
1848
1925
|
# f.close
|
|
1849
1926
|
#
|
|
1850
|
-
# *
|
|
1851
|
-
# `offset`:
|
|
1927
|
+
# * <code>:END</code> or <code>IO::SEEK_END</code>: Repositions the stream to
|
|
1928
|
+
# its end plus the given `offset`:
|
|
1852
1929
|
#
|
|
1853
1930
|
# f = File.open('t.txt')
|
|
1854
1931
|
# f.tell # => 0
|
|
@@ -1860,7 +1937,8 @@ class IO < Object
|
|
|
1860
1937
|
# f.tell # => 12
|
|
1861
1938
|
# f.close
|
|
1862
1939
|
#
|
|
1863
|
-
# *
|
|
1940
|
+
# * <code>:SET</code> or <code>IO:SEEK_SET</code>: Repositions the stream to
|
|
1941
|
+
# the given `offset`:
|
|
1864
1942
|
#
|
|
1865
1943
|
# f = File.open('t.txt')
|
|
1866
1944
|
# f.tell # => 0
|
|
@@ -1888,7 +1966,7 @@ class IO < Object
|
|
|
1888
1966
|
# Argument `int_enc`, if given, must be an Encoding object or a String with the
|
|
1889
1967
|
# encoding name; it is assigned as the encoding for the internal string.
|
|
1890
1968
|
#
|
|
1891
|
-
# Argument
|
|
1969
|
+
# Argument <code>'ext_enc:int_enc'</code>, if given, is a string containing two
|
|
1892
1970
|
# colon-separated encoding names; corresponding Encoding objects are assigned as
|
|
1893
1971
|
# the external and internal encodings for the stream.
|
|
1894
1972
|
#
|
|
@@ -1989,7 +2067,7 @@ class IO < Object
|
|
|
1989
2067
|
#
|
|
1990
2068
|
# This method should not be used with other stream-reader methods.
|
|
1991
2069
|
#
|
|
1992
|
-
def sysread: (Integer maxlen, String outbuf) -> String
|
|
2070
|
+
def sysread: (Integer maxlen, ?String? outbuf) -> String
|
|
1993
2071
|
|
|
1994
2072
|
# <!--
|
|
1995
2073
|
# rdoc-file=io.c
|
|
@@ -2258,11 +2336,11 @@ class IO < Object
|
|
|
2258
2336
|
#
|
|
2259
2337
|
# On some platforms such as Windows, write_nonblock is not supported according
|
|
2260
2338
|
# to the kind of the IO object. In such cases, write_nonblock raises
|
|
2261
|
-
#
|
|
2339
|
+
# <code>Errno::EBADF</code>.
|
|
2262
2340
|
#
|
|
2263
2341
|
# By specifying a keyword argument *exception* to `false`, you can indicate that
|
|
2264
2342
|
# write_nonblock should not raise an IO::WaitWritable exception, but return the
|
|
2265
|
-
# symbol
|
|
2343
|
+
# symbol <code>:wait_writable</code> instead.
|
|
2266
2344
|
#
|
|
2267
2345
|
def write_nonblock: (_ToS s, ?exception: true) -> Integer
|
|
2268
2346
|
| (_ToS s, exception: false) -> (Integer | :wait_writable | nil)
|
|
@@ -2274,10 +2352,6 @@ class IO < Object
|
|
|
2274
2352
|
# Behaves like IO.read, except that the stream is opened in binary mode with
|
|
2275
2353
|
# ASCII-8BIT encoding.
|
|
2276
2354
|
#
|
|
2277
|
-
# When called from class IO (but not subclasses of IO), this method has
|
|
2278
|
-
# potential security vulnerabilities if called with untrusted input; see
|
|
2279
|
-
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2280
|
-
#
|
|
2281
2355
|
def self.binread: (path name, ?Integer? length, ?Integer offset) -> String
|
|
2282
2356
|
|
|
2283
2357
|
# <!--
|
|
@@ -2287,10 +2361,6 @@ class IO < Object
|
|
|
2287
2361
|
# Behaves like IO.write, except that the stream is opened in binary mode with
|
|
2288
2362
|
# ASCII-8BIT encoding.
|
|
2289
2363
|
#
|
|
2290
|
-
# When called from class IO (but not subclasses of IO), this method has
|
|
2291
|
-
# potential security vulnerabilities if called with untrusted input; see
|
|
2292
|
-
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2293
|
-
#
|
|
2294
2364
|
def self.binwrite: (path name, _ToS string, ?Integer offset, ?mode: String mode) -> Integer
|
|
2295
2365
|
|
|
2296
2366
|
# <!--
|
|
@@ -2304,15 +2374,15 @@ class IO < Object
|
|
|
2304
2374
|
#
|
|
2305
2375
|
# * The path to a readable file, from which source data is to be read.
|
|
2306
2376
|
# * An IO-like object, opened for reading and capable of responding to
|
|
2307
|
-
# method
|
|
2377
|
+
# method <code>:readpartial</code> or method <code>:read</code>.
|
|
2308
2378
|
#
|
|
2309
2379
|
# * The given `dst` must be one of the following:
|
|
2310
2380
|
#
|
|
2311
2381
|
# * The path to a writable file, to which data is to be written.
|
|
2312
2382
|
# * An IO-like object, opened for writing and capable of responding to
|
|
2313
|
-
# method
|
|
2383
|
+
# method <code>:write</code>.
|
|
2314
2384
|
#
|
|
2315
|
-
# The examples here use file
|
|
2385
|
+
# The examples here use file <code>t.txt</code> as source:
|
|
2316
2386
|
#
|
|
2317
2387
|
# File.read('t.txt')
|
|
2318
2388
|
# # => "First line\nSecond line\n\nThird line\nFourth line\n"
|
|
@@ -2354,15 +2424,16 @@ class IO < Object
|
|
|
2354
2424
|
# connected to a new stream `io`.
|
|
2355
2425
|
#
|
|
2356
2426
|
# This method has potential security vulnerabilities if called with untrusted
|
|
2357
|
-
# input; see [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2427
|
+
# input; see [Command Injection](rdoc-ref:security/command_injection.rdoc).
|
|
2358
2428
|
#
|
|
2359
2429
|
# If no block is given, returns the new stream, which depending on given `mode`
|
|
2360
2430
|
# may be open for reading, writing, or both. The stream should be explicitly
|
|
2361
2431
|
# closed (eventually) to avoid resource leaks.
|
|
2362
2432
|
#
|
|
2363
2433
|
# If a block is given, the stream is passed to the block (again, open for
|
|
2364
|
-
# reading, writing, or both); when the block exits, the stream is closed,
|
|
2365
|
-
#
|
|
2434
|
+
# reading, writing, or both); when the block exits, the stream is closed, the
|
|
2435
|
+
# block's value is returned, and the global variable <code>$?</code> is set to
|
|
2436
|
+
# the child's exit status.
|
|
2366
2437
|
#
|
|
2367
2438
|
# Optional argument `mode` may be any valid IO mode. See [Access
|
|
2368
2439
|
# Modes](rdoc-ref:File@Access+Modes).
|
|
@@ -2391,10 +2462,10 @@ class IO < Object
|
|
|
2391
2462
|
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
|
2392
2463
|
# * Options for Kernel#spawn.
|
|
2393
2464
|
#
|
|
2394
|
-
# **Forked
|
|
2465
|
+
# **Forked Process**
|
|
2395
2466
|
#
|
|
2396
|
-
# When argument `cmd` is the 1-character string
|
|
2397
|
-
# fork:
|
|
2467
|
+
# When argument `cmd` is the 1-character string <code>'-'</code>, causes the
|
|
2468
|
+
# process to fork:
|
|
2398
2469
|
# IO.popen('-') do |pipe|
|
|
2399
2470
|
# if pipe
|
|
2400
2471
|
# $stderr.puts "In parent, child pid is #{pipe.pid}\n"
|
|
@@ -2412,8 +2483,8 @@ class IO < Object
|
|
|
2412
2483
|
#
|
|
2413
2484
|
# **Shell Subprocess**
|
|
2414
2485
|
#
|
|
2415
|
-
# When argument `cmd` is a single string (but not
|
|
2416
|
-
# `cmd` is run as a shell command:
|
|
2486
|
+
# When argument `cmd` is a single string (but not <code>'-'</code>), the program
|
|
2487
|
+
# named `cmd` is run as a shell command:
|
|
2417
2488
|
#
|
|
2418
2489
|
# IO.popen('uname') do |pipe|
|
|
2419
2490
|
# pipe.readlines
|
|
@@ -2437,8 +2508,8 @@ class IO < Object
|
|
|
2437
2508
|
#
|
|
2438
2509
|
# **Program Subprocess**
|
|
2439
2510
|
#
|
|
2440
|
-
# When argument `cmd` is an array of strings, the program named
|
|
2441
|
-
# with all elements of `cmd` as its arguments:
|
|
2511
|
+
# When argument `cmd` is an array of strings, the program named
|
|
2512
|
+
# <code>cmd[0]</code> is run with all elements of `cmd` as its arguments:
|
|
2442
2513
|
#
|
|
2443
2514
|
# IO.popen(['du', '..', '.']) do |pipe|
|
|
2444
2515
|
# $stderr.puts pipe.readlines.size
|
|
@@ -2448,18 +2519,19 @@ class IO < Object
|
|
|
2448
2519
|
#
|
|
2449
2520
|
# 1111
|
|
2450
2521
|
#
|
|
2451
|
-
#
|
|
2522
|
+
# <strong>Program Subprocess with `argv0`</strong>
|
|
2452
2523
|
#
|
|
2453
2524
|
# When argument `cmd` is an array whose first element is a 2-element string
|
|
2454
2525
|
# array and whose remaining elements (if any) are strings:
|
|
2455
2526
|
#
|
|
2456
|
-
# *
|
|
2457
|
-
# program that is run.
|
|
2458
|
-
# *
|
|
2459
|
-
# program's
|
|
2460
|
-
# *
|
|
2527
|
+
# * <code>cmd[0][0]</code> (the first string in the nested array) is the name
|
|
2528
|
+
# of a program that is run.
|
|
2529
|
+
# * <code>cmd[0][1]</code> (the second string in the nested array) is set as
|
|
2530
|
+
# the program's <code>argv[0]</code>.
|
|
2531
|
+
# * <code>cmd[1..-1]</code> (the strings in the outer array) are the program's
|
|
2532
|
+
# arguments.
|
|
2461
2533
|
#
|
|
2462
|
-
# Example (sets
|
|
2534
|
+
# Example (sets <code>$0</code> to 'foo'):
|
|
2463
2535
|
#
|
|
2464
2536
|
# IO.popen([['/bin/sh', 'foo'], '-c', 'echo $0']).read # => "foo\n"
|
|
2465
2537
|
#
|
|
@@ -2503,10 +2575,10 @@ class IO < Object
|
|
|
2503
2575
|
#
|
|
2504
2576
|
# Raises exceptions that IO.pipe and Kernel.spawn raise.
|
|
2505
2577
|
#
|
|
2506
|
-
def self.popen: (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others:
|
|
2507
|
-
| (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others:
|
|
2508
|
-
| [X] (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others:
|
|
2509
|
-
| [X] (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others:
|
|
2578
|
+
def self.popen: (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) -> instance
|
|
2579
|
+
| (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) -> instance
|
|
2580
|
+
| [X] (string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) { (instance) -> X } -> X
|
|
2581
|
+
| [X] (Hash[string, string?] env, string | cmd_array cmd, ?string | int mode, ?path: string?, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?unsetenv_others: bool, ?pgroup: true | Integer, ?umask: Integer, ?in: Kernel::redirect_fd, ?out: Kernel::redirect_fd, ?err: Kernel::redirect_fd, ?close_others: bool, ?chdir: String) { (instance) -> X } -> X
|
|
2510
2582
|
|
|
2511
2583
|
# The command can be given as:
|
|
2512
2584
|
#
|
|
@@ -2526,10 +2598,6 @@ class IO < Object
|
|
|
2526
2598
|
# -->
|
|
2527
2599
|
# Calls the block with each successive line read from the stream.
|
|
2528
2600
|
#
|
|
2529
|
-
# When called from class IO (but not subclasses of IO), this method has
|
|
2530
|
-
# potential security vulnerabilities if called with untrusted input; see
|
|
2531
|
-
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2532
|
-
#
|
|
2533
2601
|
# The first argument must be a string that is the path to a file.
|
|
2534
2602
|
#
|
|
2535
2603
|
# With only argument `path` given, parses lines from the file at the given
|
|
@@ -2594,8 +2662,8 @@ class IO < Object
|
|
|
2594
2662
|
#
|
|
2595
2663
|
# Returns an Enumerator if no block is given.
|
|
2596
2664
|
#
|
|
2597
|
-
def self.foreach: (
|
|
2598
|
-
| (
|
|
2665
|
+
def self.foreach: (path path, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) { (String line) -> void } -> nil
|
|
2666
|
+
| (path path, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> ::Enumerator[String, nil]
|
|
2599
2667
|
|
|
2600
2668
|
# <!--
|
|
2601
2669
|
# rdoc-file=io.c
|
|
@@ -2651,8 +2719,8 @@ class IO < Object
|
|
|
2651
2719
|
# In the example below, the two processes close the ends of the pipe that they
|
|
2652
2720
|
# are not using. This is not just a cosmetic nicety. The read end of a pipe will
|
|
2653
2721
|
# not generate an end of file condition if there are any writers with the pipe
|
|
2654
|
-
# still open. In the case of the parent process, the
|
|
2655
|
-
# if it does not first issue a
|
|
2722
|
+
# still open. In the case of the parent process, the <code>rd.read</code> will
|
|
2723
|
+
# never return if it does not first issue a <code>wr.close</code>:
|
|
2656
2724
|
#
|
|
2657
2725
|
# rd, wr = IO.pipe
|
|
2658
2726
|
#
|
|
@@ -2668,7 +2736,7 @@ class IO < Object
|
|
|
2668
2736
|
# wr.close
|
|
2669
2737
|
# end
|
|
2670
2738
|
#
|
|
2671
|
-
#
|
|
2739
|
+
# <em>produces:</em>
|
|
2672
2740
|
#
|
|
2673
2741
|
# Sending message to parent
|
|
2674
2742
|
# Parent got: <Hi Dad>
|
|
@@ -2683,10 +2751,6 @@ class IO < Object
|
|
|
2683
2751
|
# Opens the stream, reads and returns some or all of its content, and closes the
|
|
2684
2752
|
# stream; returns `nil` if no bytes were read.
|
|
2685
2753
|
#
|
|
2686
|
-
# When called from class IO (but not subclasses of IO), this method has
|
|
2687
|
-
# potential security vulnerabilities if called with untrusted input; see
|
|
2688
|
-
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2689
|
-
#
|
|
2690
2754
|
# The first argument must be a string that is the path to a file.
|
|
2691
2755
|
#
|
|
2692
2756
|
# With only argument `path` given, reads in text mode and returns the entire
|
|
@@ -2726,10 +2790,6 @@ class IO < Object
|
|
|
2726
2790
|
# -->
|
|
2727
2791
|
# Returns an array of all lines read from the stream.
|
|
2728
2792
|
#
|
|
2729
|
-
# When called from class IO (but not subclasses of IO), this method has
|
|
2730
|
-
# potential security vulnerabilities if called with untrusted input; see
|
|
2731
|
-
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2732
|
-
#
|
|
2733
2793
|
# The first argument must be a string that is the path to a file.
|
|
2734
2794
|
#
|
|
2735
2795
|
# With only argument `path` given, parses lines from the file at the given
|
|
@@ -2769,7 +2829,7 @@ class IO < Object
|
|
|
2769
2829
|
# * [Encoding options](rdoc-ref:encodings.rdoc@Encoding+Options).
|
|
2770
2830
|
# * [Line Options](rdoc-ref:IO@Line+IO).
|
|
2771
2831
|
#
|
|
2772
|
-
def self.readlines: (
|
|
2832
|
+
def self.readlines: (path name, ?String sep, ?Integer limit, ?external_encoding: String | Encoding | nil, ?internal_encoding: String | Encoding | nil, ?encoding: String | Encoding | nil, ?textmode: boolish, ?binmode: boolish, ?autoclose: boolish, ?mode: String, ?chomp: boolish) -> ::Array[String]
|
|
2773
2833
|
|
|
2774
2834
|
# <!--
|
|
2775
2835
|
# rdoc-file=io.c
|
|
@@ -2785,7 +2845,9 @@ class IO < Object
|
|
|
2785
2845
|
# IO objects.
|
|
2786
2846
|
#
|
|
2787
2847
|
# Argument `timeout` is a numeric value (such as integer or float) timeout
|
|
2788
|
-
# interval in seconds.
|
|
2848
|
+
# interval in seconds. `timeout` can also be `nil` or
|
|
2849
|
+
# <code>Float::INFINITY</code>. `nil` and <code>Float::INFINITY</code> means no
|
|
2850
|
+
# timeout.
|
|
2789
2851
|
#
|
|
2790
2852
|
# The method monitors the IO objects given in all three arrays, waiting for some
|
|
2791
2853
|
# to be ready; returns a 3-element array whose elements are:
|
|
@@ -2860,8 +2922,8 @@ class IO < Object
|
|
|
2860
2922
|
#
|
|
2861
2923
|
# The writability notified by select(2) doesn't show how many bytes are
|
|
2862
2924
|
# writable. IO#write method blocks until given whole string is written. So,
|
|
2863
|
-
#
|
|
2864
|
-
# IO.select. IO#write_nonblock is required to avoid the blocking.
|
|
2925
|
+
# <code>IO#write(two or more bytes)</code> can block after writability is
|
|
2926
|
+
# notified by IO.select. IO#write_nonblock is required to avoid the blocking.
|
|
2865
2927
|
#
|
|
2866
2928
|
# Blocking write (#write) can be emulated using #write_nonblock and IO.select as
|
|
2867
2929
|
# follows: IO::WaitReadable should also be rescued for SSL renegotiation in
|
|
@@ -2950,10 +3012,6 @@ class IO < Object
|
|
|
2950
3012
|
# Opens the stream, writes the given `data` to it, and closes the stream;
|
|
2951
3013
|
# returns the number of bytes written.
|
|
2952
3014
|
#
|
|
2953
|
-
# When called from class IO (but not subclasses of IO), this method has
|
|
2954
|
-
# potential security vulnerabilities if called with untrusted input; see
|
|
2955
|
-
# [Command Injection](rdoc-ref:command_injection.rdoc).
|
|
2956
|
-
#
|
|
2957
3015
|
# The first argument must be a string that is the path to a file.
|
|
2958
3016
|
#
|
|
2959
3017
|
# With only argument `path` given, writes the given `data` to the file at that
|
|
@@ -2976,7 +3034,7 @@ class IO < Object
|
|
|
2976
3034
|
# File.read('t.tmp') # => "ab012f"
|
|
2977
3035
|
#
|
|
2978
3036
|
# If `offset` is outside the file content, the file is padded with null
|
|
2979
|
-
# characters
|
|
3037
|
+
# characters <code>"\u0000"</code>:
|
|
2980
3038
|
#
|
|
2981
3039
|
# IO.write('t.tmp', 'xyz', 10) # => 3
|
|
2982
3040
|
# File.read('t.tmp') # => "ab012f\u0000\u0000\u0000\u0000xyz"
|
|
@@ -3015,7 +3073,8 @@ class IO < Object
|
|
|
3015
3073
|
# Calls the block with each remaining line read from the stream; returns `self`.
|
|
3016
3074
|
# Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
|
|
3017
3075
|
#
|
|
3018
|
-
# With no arguments given, reads lines as determined by line separator
|
|
3076
|
+
# With no arguments given, reads lines as determined by line separator
|
|
3077
|
+
# <code>$/</code>:
|
|
3019
3078
|
#
|
|
3020
3079
|
# f = File.new('t.txt')
|
|
3021
3080
|
# f.each_line {|line| p line }
|
|
@@ -3117,7 +3176,8 @@ class IO < Object
|
|
|
3117
3176
|
# Calls the block with each remaining line read from the stream; returns `self`.
|
|
3118
3177
|
# Does nothing if already at end-of-stream; See [Line IO](rdoc-ref:IO@Line+IO).
|
|
3119
3178
|
#
|
|
3120
|
-
# With no arguments given, reads lines as determined by line separator
|
|
3179
|
+
# With no arguments given, reads lines as determined by line separator
|
|
3180
|
+
# <code>$/</code>:
|
|
3121
3181
|
#
|
|
3122
3182
|
# f = File.new('t.txt')
|
|
3123
3183
|
# f.each_line {|line| p line }
|
|
@@ -3404,3 +3464,9 @@ end
|
|
|
3404
3464
|
#
|
|
3405
3465
|
module IO::WaitWritable
|
|
3406
3466
|
end
|
|
3467
|
+
|
|
3468
|
+
# <!-- rdoc-file=io.c -->
|
|
3469
|
+
# Can be raised by IO operations when IO#timeout= is set.
|
|
3470
|
+
#
|
|
3471
|
+
class IO::TimeoutError < IOError
|
|
3472
|
+
end
|