rbs 3.10.4 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/dependabot.yml +14 -14
- data/.github/workflows/bundle-update.yml +60 -0
- data/.github/workflows/c-check.yml +7 -5
- data/.github/workflows/comments.yml +2 -2
- data/.github/workflows/dependabot.yml +2 -2
- data/.github/workflows/ruby.yml +16 -26
- data/.github/workflows/rust.yml +95 -0
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +2 -2
- data/.rubocop.yml +2 -2
- data/.vscode/extensions.json +5 -0
- data/.vscode/settings.json +19 -0
- data/CHANGELOG.md +202 -2
- data/Rakefile +9 -23
- data/Steepfile +2 -0
- data/config.yml +457 -13
- data/core/array.rbs +218 -188
- data/core/basic_object.rbs +9 -8
- data/core/binding.rbs +0 -2
- data/core/builtin.rbs +2 -2
- data/core/class.rbs +6 -5
- data/core/comparable.rbs +45 -31
- data/core/complex.rbs +66 -55
- data/core/dir.rbs +57 -45
- data/core/encoding.rbs +6 -6
- data/core/enumerable.rbs +105 -91
- data/core/enumerator/arithmetic_sequence.rbs +70 -0
- data/core/enumerator.rbs +24 -3
- data/core/errno.rbs +3 -2
- data/core/errors.rbs +31 -29
- data/core/exception.rbs +12 -12
- data/core/fiber.rbs +47 -36
- data/core/file.rbs +242 -169
- data/core/file_test.rbs +2 -2
- data/core/float.rbs +42 -68
- data/core/gc.rbs +78 -70
- data/core/hash.rbs +70 -60
- data/core/integer.rbs +32 -75
- data/core/io/buffer.rbs +36 -36
- data/core/io/wait.rbs +7 -7
- data/core/io.rbs +192 -146
- data/core/kernel.rbs +198 -147
- data/core/marshal.rbs +3 -3
- data/core/match_data.rbs +14 -12
- data/core/math.rbs +69 -67
- data/core/method.rbs +6 -8
- data/core/module.rbs +148 -88
- data/core/nil_class.rbs +4 -3
- data/core/numeric.rbs +53 -50
- data/core/object.rbs +6 -8
- data/core/object_space.rbs +11 -10
- data/core/pathname.rbs +131 -81
- data/core/proc.rbs +65 -34
- data/core/process.rbs +221 -201
- data/core/ractor.rbs +15 -11
- data/core/random.rbs +21 -3
- data/core/range.rbs +152 -49
- data/core/rational.rbs +5 -56
- data/core/rbs/unnamed/argf.rbs +58 -51
- data/core/rbs/unnamed/env_class.rbs +18 -13
- data/core/rbs/unnamed/main_class.rbs +123 -0
- data/core/rbs/unnamed/random.rbs +7 -116
- data/core/regexp.rbs +236 -197
- data/core/ruby.rbs +1 -1
- data/core/ruby_vm.rbs +32 -30
- data/core/rubygems/config_file.rbs +5 -5
- data/core/rubygems/errors.rbs +1 -1
- data/core/rubygems/requirement.rbs +5 -5
- data/core/rubygems/rubygems.rbs +5 -3
- data/core/set.rbs +17 -16
- data/core/signal.rbs +2 -2
- data/core/string.rbs +318 -298
- data/core/struct.rbs +26 -25
- data/core/symbol.rbs +25 -24
- data/core/thread.rbs +40 -41
- data/core/time.rbs +47 -42
- data/core/trace_point.rbs +34 -31
- data/core/true_class.rbs +2 -2
- data/core/unbound_method.rbs +10 -10
- data/core/warning.rbs +7 -7
- data/docs/collection.md +1 -1
- data/docs/config.md +171 -0
- data/docs/inline.md +576 -0
- data/docs/syntax.md +46 -16
- data/docs/type_fingerprint.md +21 -0
- data/exe/rbs +1 -1
- data/ext/rbs_extension/ast_translation.c +595 -98
- data/ext/rbs_extension/class_constants.c +30 -0
- data/ext/rbs_extension/class_constants.h +15 -0
- data/ext/rbs_extension/legacy_location.c +30 -53
- data/ext/rbs_extension/legacy_location.h +37 -0
- data/ext/rbs_extension/main.c +125 -24
- data/include/rbs/ast.h +485 -150
- data/include/rbs/lexer.h +11 -4
- data/include/rbs/location.h +25 -44
- data/include/rbs/parser.h +20 -2
- data/include/rbs/util/rbs_constant_pool.h +0 -3
- data/include/rbs.h +8 -0
- 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 +409 -0
- data/lib/rbs/ast/ruby/comment_block.rb +245 -0
- data/lib/rbs/ast/ruby/declarations.rb +281 -0
- data/lib/rbs/ast/ruby/helpers/constant_helper.rb +28 -0
- data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
- data/lib/rbs/ast/ruby/members.rb +723 -0
- data/lib/rbs/ast/type_param.rb +24 -4
- data/lib/rbs/buffer.rb +105 -20
- data/lib/rbs/cli/diff.rb +16 -15
- data/lib/rbs/cli/validate.rb +62 -125
- data/lib/rbs/cli.rb +55 -23
- data/lib/rbs/collection/config/lockfile_generator.rb +8 -4
- data/lib/rbs/collection/sources/git.rb +1 -0
- data/lib/rbs/collection.rb +0 -1
- data/lib/rbs/definition.rb +6 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +119 -63
- data/lib/rbs/definition_builder/method_builder.rb +65 -30
- data/lib/rbs/definition_builder.rb +177 -20
- data/lib/rbs/diff.rb +7 -1
- data/lib/rbs/environment/class_entry.rb +69 -0
- data/lib/rbs/environment/module_entry.rb +66 -0
- data/lib/rbs/environment.rb +338 -155
- data/lib/rbs/environment_loader.rb +2 -2
- data/lib/rbs/errors.rb +30 -20
- data/lib/rbs/inline_parser/comment_association.rb +117 -0
- data/lib/rbs/inline_parser.rb +542 -0
- data/lib/rbs/location_aux.rb +36 -4
- data/lib/rbs/locator.rb +5 -1
- data/lib/rbs/method_type.rb +5 -3
- data/lib/rbs/namespace.rb +0 -7
- data/lib/rbs/parser_aux.rb +31 -8
- 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 -2
- data/lib/rbs/resolver/type_name_resolver.rb +0 -8
- data/lib/rbs/source.rb +99 -0
- data/lib/rbs/subtractor.rb +4 -3
- data/lib/rbs/test/type_check.rb +5 -2
- data/lib/rbs/type_name.rb +1 -8
- data/lib/rbs/types.rb +88 -78
- data/lib/rbs/unit_test/convertibles.rb +1 -0
- data/lib/rbs/unit_test/type_assertions.rb +35 -8
- data/lib/rbs/validator.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +12 -1
- data/rbs.gemspec +3 -2
- data/rust/.gitignore +1 -0
- data/rust/Cargo.lock +378 -0
- data/rust/Cargo.toml +7 -0
- data/rust/ruby-rbs/Cargo.toml +22 -0
- data/rust/ruby-rbs/build.rs +764 -0
- data/rust/ruby-rbs/examples/locations.rs +60 -0
- data/rust/ruby-rbs/src/lib.rs +1 -0
- data/rust/ruby-rbs/src/node/mod.rs +742 -0
- data/rust/ruby-rbs/tests/sanity.rs +47 -0
- data/rust/ruby-rbs/vendor/rbs/config.yml +1 -0
- data/rust/ruby-rbs-sys/Cargo.toml +23 -0
- data/rust/ruby-rbs-sys/build.rs +204 -0
- data/rust/ruby-rbs-sys/src/lib.rs +50 -0
- data/rust/ruby-rbs-sys/vendor/rbs/include +1 -0
- data/rust/ruby-rbs-sys/vendor/rbs/src +1 -0
- data/rust/ruby-rbs-sys/wrapper.h +1 -0
- data/schema/typeParam.json +17 -1
- data/sig/ancestor_builder.rbs +1 -1
- data/sig/ast/ruby/annotations.rbs +421 -0
- data/sig/ast/ruby/comment_block.rbs +127 -0
- data/sig/ast/ruby/declarations.rbs +158 -0
- data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
- data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
- data/sig/ast/ruby/members.rbs +178 -0
- data/sig/buffer.rbs +63 -5
- data/sig/cli/diff.rbs +5 -11
- data/sig/cli/validate.rbs +12 -8
- data/sig/cli.rbs +18 -18
- data/sig/definition.rbs +6 -0
- data/sig/definition_builder.rbs +3 -1
- data/sig/environment/class_entry.rbs +50 -0
- data/sig/environment/module_entry.rbs +50 -0
- data/sig/environment.rbs +37 -81
- data/sig/errors.rbs +26 -20
- data/sig/inline_parser/comment_association.rbs +71 -0
- data/sig/inline_parser.rbs +124 -0
- data/sig/location.rbs +32 -7
- data/sig/locator.rbs +0 -2
- data/sig/method_builder.rbs +9 -4
- data/sig/namespace.rbs +0 -5
- data/sig/parser.rbs +47 -13
- data/sig/prototype/helpers.rbs +2 -0
- data/sig/resolver/type_name_resolver.rbs +0 -3
- data/sig/source.rbs +48 -0
- data/sig/type_param.rbs +13 -8
- data/sig/typename.rbs +0 -5
- data/sig/types.rbs +6 -7
- data/sig/unit_test/spy.rbs +0 -8
- data/sig/unit_test/type_assertions.rbs +11 -0
- data/src/ast.c +491 -143
- data/src/lexer.c +1552 -1314
- data/src/lexer.re +7 -0
- data/src/lexstate.c +8 -1
- data/src/location.c +8 -48
- data/src/parser.c +1107 -409
- data/src/util/rbs_constant_pool.c +0 -4
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -16
- data/stdlib/cgi-escape/0/escape.rbs +4 -4
- data/stdlib/coverage/0/coverage.rbs +4 -3
- data/stdlib/date/0/date.rbs +33 -28
- data/stdlib/date/0/date_time.rbs +24 -23
- data/stdlib/did_you_mean/0/did_you_mean.rbs +17 -16
- data/stdlib/digest/0/digest.rbs +110 -0
- data/stdlib/erb/0/erb.rbs +64 -53
- data/stdlib/etc/0/etc.rbs +55 -50
- data/stdlib/fileutils/0/fileutils.rbs +140 -126
- data/stdlib/forwardable/0/forwardable.rbs +10 -10
- data/stdlib/io-console/0/io-console.rbs +2 -2
- data/stdlib/json/0/json.rbs +158 -131
- data/stdlib/monitor/0/monitor.rbs +3 -3
- data/stdlib/net-http/0/net-http.rbs +159 -134
- data/stdlib/objspace/0/objspace.rbs +8 -30
- data/stdlib/open-uri/0/open-uri.rbs +8 -8
- data/stdlib/open3/0/open3.rbs +469 -10
- data/stdlib/openssl/0/openssl.rbs +144 -129
- data/stdlib/optparse/0/optparse.rbs +23 -14
- data/stdlib/pathname/0/pathname.rbs +2 -2
- 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 +62 -9
- 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/store.rbs +1 -1
- data/stdlib/ripper/0/ripper.rbs +20 -17
- data/stdlib/securerandom/0/manifest.yaml +2 -0
- data/stdlib/securerandom/0/securerandom.rbs +7 -20
- data/stdlib/shellwords/0/shellwords.rbs +2 -2
- data/stdlib/socket/0/addrinfo.rbs +9 -9
- data/stdlib/socket/0/basic_socket.rbs +3 -3
- data/stdlib/socket/0/ip_socket.rbs +10 -8
- data/stdlib/socket/0/socket.rbs +10 -9
- data/stdlib/socket/0/tcp_server.rbs +1 -1
- data/stdlib/socket/0/tcp_socket.rbs +1 -1
- data/stdlib/socket/0/udp_socket.rbs +1 -1
- data/stdlib/socket/0/unix_server.rbs +1 -1
- data/stdlib/stringio/0/stringio.rbs +55 -54
- data/stdlib/strscan/0/string_scanner.rbs +46 -44
- data/stdlib/tempfile/0/tempfile.rbs +24 -20
- data/stdlib/time/0/time.rbs +7 -5
- data/stdlib/tsort/0/tsort.rbs +7 -6
- data/stdlib/uri/0/common.rbs +31 -18
- data/stdlib/uri/0/file.rbs +2 -2
- data/stdlib/uri/0/generic.rbs +9 -2
- 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 +6 -5
- data/stdlib/zlib/0/deflate.rbs +4 -3
- data/stdlib/zlib/0/gzip_reader.rbs +6 -6
- 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
- metadata +66 -3
|
@@ -6,8 +6,8 @@
|
|
|
6
6
|
# * StringIO.new: returns a new StringIO object containing the given string.
|
|
7
7
|
# * StringIO.open: passes a new StringIO object to the given block.
|
|
8
8
|
# Like an IO stream, a StringIO stream has certain properties:
|
|
9
|
-
# *
|
|
10
|
-
# etc.;
|
|
9
|
+
# * <strong>Read/write mode</strong>: whether the stream may be read, written,
|
|
10
|
+
# appended to, etc.;
|
|
11
11
|
# see [Read/Write Mode](rdoc-ref:StringIO@Read-2FWrite+Mode).
|
|
12
12
|
# * **Data mode**: text-only or binary;
|
|
13
13
|
# see [Data Mode](rdoc-ref:StringIO@Data+Mode).
|
|
@@ -18,8 +18,8 @@
|
|
|
18
18
|
# * **Line number**: a special, line-oriented, "position" (different from the
|
|
19
19
|
# position mentioned above);
|
|
20
20
|
# see [Line Number](rdoc-ref:StringIO@Line+Number).
|
|
21
|
-
# *
|
|
22
|
-
# writing.
|
|
21
|
+
# * <strong>Open/closed</strong>: whether the stream is open or closed, for
|
|
22
|
+
# reading or writing.
|
|
23
23
|
# see [Open/Closed Streams](rdoc-ref:StringIO@Open-2FClosed+Streams).
|
|
24
24
|
# * **BOM**: byte mark order;
|
|
25
25
|
# see [Byte Order Mark](rdoc-ref:StringIO@BOM+-28Byte+Order+Mark-29).
|
|
@@ -39,24 +39,24 @@
|
|
|
39
39
|
# ## Stream Properties
|
|
40
40
|
# ### Read/Write Mode
|
|
41
41
|
# #### Summary
|
|
42
|
-
#
|
|
43
|
-
#
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
#
|
|
47
|
-
#
|
|
48
|
-
#
|
|
49
|
-
#
|
|
42
|
+
# Mode |Initial Clear?| Read | Write
|
|
43
|
+
# ------------------------------|--------------|--------|--------
|
|
44
|
+
# <code>'r'</code>: read-only | No |Anywhere| Error
|
|
45
|
+
# <code>'w'</code>: write-only | Yes | Error |Anywhere
|
|
46
|
+
# <code>'a'</code>: append-only | No | Error |End only
|
|
47
|
+
# <code>'r+'</code>: read/write | No |Anywhere|Anywhere
|
|
48
|
+
# <code>'w+'</code>: read-write | Yes |Anywhere|Anywhere
|
|
49
|
+
# <code>'a+'</code>: read/append| No |Anywhere|End only
|
|
50
50
|
# Each section below describes a read/write mode.
|
|
51
51
|
# Any of the modes may be given as a string or as file constants;
|
|
52
52
|
# example:
|
|
53
53
|
# strio = StringIO.new('foo', 'a')
|
|
54
54
|
# strio = StringIO.new('foo', File::WRONLY | File::APPEND)
|
|
55
55
|
#
|
|
56
|
-
# ####
|
|
56
|
+
# #### <code>'r'</code>: Read-Only
|
|
57
57
|
# Mode specified as one of:
|
|
58
|
-
# * String:
|
|
59
|
-
# * Constant:
|
|
58
|
+
# * String: <code>'r'</code>.
|
|
59
|
+
# * Constant: <code>File::RDONLY</code>.
|
|
60
60
|
# Initial state:
|
|
61
61
|
# strio = StringIO.new('foobarbaz', 'r')
|
|
62
62
|
# strio.pos # => 0 # Beginning-of-stream.
|
|
@@ -71,10 +71,10 @@
|
|
|
71
71
|
# May not be written:
|
|
72
72
|
# strio.write('foo') # Raises IOError: not opened for writing
|
|
73
73
|
#
|
|
74
|
-
# ####
|
|
74
|
+
# #### <code>'w'</code>: Write-Only
|
|
75
75
|
# Mode specified as one of:
|
|
76
|
-
# * String:
|
|
77
|
-
# * Constant:
|
|
76
|
+
# * String: <code>'w'</code>.
|
|
77
|
+
# * Constant: <code>File::WRONLY</code>.
|
|
78
78
|
# Initial state:
|
|
79
79
|
# strio = StringIO.new('foo', 'w')
|
|
80
80
|
# strio.pos # => 0 # Beginning of stream.
|
|
@@ -96,10 +96,10 @@
|
|
|
96
96
|
# May not be read:
|
|
97
97
|
# strio.read # Raises IOError: not opened for reading
|
|
98
98
|
#
|
|
99
|
-
# ####
|
|
99
|
+
# #### <code>'a'</code>: Append-Only
|
|
100
100
|
# Mode specified as one of:
|
|
101
|
-
# * String:
|
|
102
|
-
# * Constant:
|
|
101
|
+
# * String: <code>'a'</code>.
|
|
102
|
+
# * Constant: <code>File::WRONLY | File::APPEND</code>.
|
|
103
103
|
# Initial state:
|
|
104
104
|
# strio = StringIO.new('foo', 'a')
|
|
105
105
|
# strio.pos # => 0 # Beginning-of-stream.
|
|
@@ -117,10 +117,10 @@
|
|
|
117
117
|
# May not be read:
|
|
118
118
|
# strio.gets # Raises IOError: not opened for reading
|
|
119
119
|
#
|
|
120
|
-
# ####
|
|
120
|
+
# #### <code>'r+'</code>: Read/Write
|
|
121
121
|
# Mode specified as one of:
|
|
122
|
-
# * String:
|
|
123
|
-
# * Constant:
|
|
122
|
+
# * String: <code>'r+'</code>.
|
|
123
|
+
# * Constant: <code>File::RDRW</code>.
|
|
124
124
|
# Initial state:
|
|
125
125
|
# strio = StringIO.new('foobar', 'r+')
|
|
126
126
|
# strio.pos # => 0 # Beginning-of-stream.
|
|
@@ -145,10 +145,10 @@
|
|
|
145
145
|
# strio.pos = 400
|
|
146
146
|
# strio.gets(3) # => nil
|
|
147
147
|
#
|
|
148
|
-
# ####
|
|
148
|
+
# #### <code>'w+'</code>: Read/Write (Initially Clear)
|
|
149
149
|
# Mode specified as one of:
|
|
150
|
-
# * String:
|
|
151
|
-
# * Constant:
|
|
150
|
+
# * String: <code>'w+'</code>.
|
|
151
|
+
# * Constant: <code>File::RDWR | File::TRUNC</code>.
|
|
152
152
|
# Initial state:
|
|
153
153
|
# strio = StringIO.new('foo', 'w+')
|
|
154
154
|
# strio.pos # => 0 # Beginning-of-stream.
|
|
@@ -177,10 +177,10 @@
|
|
|
177
177
|
# strio.pos = 400
|
|
178
178
|
# strio.gets(3) # => nil
|
|
179
179
|
#
|
|
180
|
-
# ####
|
|
180
|
+
# #### <code>'a+'</code>: Read/Append
|
|
181
181
|
# Mode specified as one of:
|
|
182
|
-
# * String:
|
|
183
|
-
# * Constant:
|
|
182
|
+
# * String: <code>'a+'</code>.
|
|
183
|
+
# * Constant: <code>File::RDWR | File::APPEND</code>.
|
|
184
184
|
# Initial state:
|
|
185
185
|
# strio = StringIO.new('foo', 'a+')
|
|
186
186
|
# strio.pos # => 0 # Beginning-of-stream.
|
|
@@ -208,9 +208,9 @@
|
|
|
208
208
|
# To specify whether the stream is to be treated as text or as binary data,
|
|
209
209
|
# either of the following may be suffixed to any of the string read/write modes
|
|
210
210
|
# above:
|
|
211
|
-
# *
|
|
211
|
+
# * <code>'t'</code>: Text;
|
|
212
212
|
# initializes the encoding as Encoding::UTF_8.
|
|
213
|
-
# *
|
|
213
|
+
# * <code>'b'</code>: Binary;
|
|
214
214
|
# initializes the encoding as Encoding::ASCII_8BIT.
|
|
215
215
|
# If neither is given, the stream defaults to text data.
|
|
216
216
|
# Examples:
|
|
@@ -231,12 +231,12 @@
|
|
|
231
231
|
# .
|
|
232
232
|
# The initial encoding for a new or re-opened stream depends on its [data
|
|
233
233
|
# mode](rdoc-ref:StringIO@Data+Mode):
|
|
234
|
-
# * Text:
|
|
235
|
-
# * Binary:
|
|
234
|
+
# * Text: <code>Encoding::UTF_8</code>.
|
|
235
|
+
# * Binary: <code>Encoding::ASCII_8BIT</code>.
|
|
236
236
|
# These instance methods are relevant:
|
|
237
237
|
# * #external_encoding: returns the current encoding of the stream as an
|
|
238
238
|
# `Encoding` object.
|
|
239
|
-
# * #internal_encoding: returns
|
|
239
|
+
# * #internal_encoding: returns +nil+; a stream does not have an internal
|
|
240
240
|
# encoding.
|
|
241
241
|
# * #set_encoding: sets the encoding for the stream.
|
|
242
242
|
# * #set_encoding_by_bom: sets the encoding for the stream to the stream's BOM
|
|
@@ -371,7 +371,7 @@
|
|
|
371
371
|
# * Method #lineno= sets the line number.
|
|
372
372
|
# The line number can be affected by reading (but never by writing);
|
|
373
373
|
# in general, the line number is incremented each time the record separator
|
|
374
|
-
# (default:
|
|
374
|
+
# (default: <code>"\n"</code>) is read.
|
|
375
375
|
# Examples:
|
|
376
376
|
# strio = StringIO.new(TEXT)
|
|
377
377
|
# strio.string # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
@@ -522,7 +522,7 @@ class StringIO
|
|
|
522
522
|
# strio.closed_write? # => false
|
|
523
523
|
# strio.close
|
|
524
524
|
#
|
|
525
|
-
# If `string` is frozen, the default `mode` is
|
|
525
|
+
# If `string` is frozen, the default `mode` is <code>'r'</code>:
|
|
526
526
|
#
|
|
527
527
|
# strio = StringIO.new('foo'.freeze)
|
|
528
528
|
# strio.string # => "foo"
|
|
@@ -546,7 +546,8 @@ class StringIO
|
|
|
546
546
|
# - StringIO.open(string = '', mode = 'r+') -> new_stringio
|
|
547
547
|
# - StringIO.open(string = '', mode = 'r+') {|strio| ... } -> object
|
|
548
548
|
# -->
|
|
549
|
-
# Creates new StringIO instance by calling
|
|
549
|
+
# Creates new StringIO instance by calling <code>StringIO.new(string,
|
|
550
|
+
# mode)</code>.
|
|
550
551
|
#
|
|
551
552
|
# With no block given, returns the new instance:
|
|
552
553
|
#
|
|
@@ -685,7 +686,7 @@ class StringIO
|
|
|
685
686
|
# **No Arguments**
|
|
686
687
|
# With no arguments given,
|
|
687
688
|
# reads lines using the default record separator
|
|
688
|
-
# (global variable
|
|
689
|
+
# (global variable <code>$/</code>, whose initial value is <code>"\n"</code>).
|
|
689
690
|
# strio = StringIO.new(TEXT)
|
|
690
691
|
# strio.each_line {|line| p line }
|
|
691
692
|
# strio.eof? # => true
|
|
@@ -697,7 +698,7 @@ class StringIO
|
|
|
697
698
|
# "Fourth line\n"
|
|
698
699
|
# "Fifth line\n"
|
|
699
700
|
#
|
|
700
|
-
#
|
|
701
|
+
# <strong>Argument `sep`</strong>
|
|
701
702
|
# With only string argument `sep` given,
|
|
702
703
|
# reads lines using that string as the record separator:
|
|
703
704
|
# strio = StringIO.new(TEXT)
|
|
@@ -710,7 +711,7 @@ class StringIO
|
|
|
710
711
|
# "line\nFifth "
|
|
711
712
|
# "line\n"
|
|
712
713
|
#
|
|
713
|
-
#
|
|
714
|
+
# <strong>Argument `limit`</strong>
|
|
714
715
|
# With only integer argument `limit` given,
|
|
715
716
|
# reads lines using the default record separator;
|
|
716
717
|
# also limits the size (in characters) of each line to the given limit:
|
|
@@ -728,7 +729,7 @@ class StringIO
|
|
|
728
729
|
# "Fifth line"
|
|
729
730
|
# "\n"
|
|
730
731
|
#
|
|
731
|
-
#
|
|
732
|
+
# <strong>Arguments `sep` and `limit`</strong>
|
|
732
733
|
# With arguments `sep` and `limit` both given,
|
|
733
734
|
# honors both:
|
|
734
735
|
# strio = StringIO.new(TEXT)
|
|
@@ -793,7 +794,7 @@ class StringIO
|
|
|
793
794
|
# Output:
|
|
794
795
|
# "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
795
796
|
#
|
|
796
|
-
#
|
|
797
|
+
# <strong>Keyword Argument `chomp`</strong>
|
|
797
798
|
# With keyword argument `chomp` given as `true` (the default is `false`),
|
|
798
799
|
# removes trailing newline (if any) from each line:
|
|
799
800
|
# strio = StringIO.new(TEXT)
|
|
@@ -1085,10 +1086,10 @@ class StringIO
|
|
|
1085
1086
|
# Side effects:
|
|
1086
1087
|
#
|
|
1087
1088
|
# * Increments stream position by the number of bytes read.
|
|
1088
|
-
# * Assigns the return value to global variable
|
|
1089
|
+
# * Assigns the return value to global variable <code>$_</code>.
|
|
1089
1090
|
#
|
|
1090
1091
|
# With no arguments given, reads a line using the default record separator
|
|
1091
|
-
# (global variable
|
|
1092
|
+
# (global variable <code>$/</code>,* whose initial value is <code>"\n"</code>):
|
|
1092
1093
|
#
|
|
1093
1094
|
# strio = StringIO.new(TEXT)
|
|
1094
1095
|
# strio.pos # => 0
|
|
@@ -1105,7 +1106,7 @@ class StringIO
|
|
|
1105
1106
|
# strio.gets # => "Привет"
|
|
1106
1107
|
# strio.pos # => 12
|
|
1107
1108
|
#
|
|
1108
|
-
#
|
|
1109
|
+
# <strong>Argument `sep`</strong>
|
|
1109
1110
|
#
|
|
1110
1111
|
# With only string argument `sep` given, reads a line using that string as the
|
|
1111
1112
|
# record separator:
|
|
@@ -1115,7 +1116,7 @@ class StringIO
|
|
|
1115
1116
|
# strio.gets(' ') # => "line\nSecond "
|
|
1116
1117
|
# strio.gets(' ') # => "line\n\nFourth "
|
|
1117
1118
|
#
|
|
1118
|
-
#
|
|
1119
|
+
# <strong>Argument `limit`</strong>
|
|
1119
1120
|
#
|
|
1120
1121
|
# With only integer argument `limit` given, reads a line using the default
|
|
1121
1122
|
# record separator; limits the size (in characters) of each line to the given
|
|
@@ -1127,7 +1128,7 @@ class StringIO
|
|
|
1127
1128
|
# strio.gets(10) # => "Second lin"
|
|
1128
1129
|
# strio.gets(10) # => "e\n"
|
|
1129
1130
|
#
|
|
1130
|
-
#
|
|
1131
|
+
# <strong>Arguments `sep` and `limit`</strong>
|
|
1131
1132
|
#
|
|
1132
1133
|
# With arguments `sep` and `limit` both given, honors both:
|
|
1133
1134
|
#
|
|
@@ -1170,7 +1171,7 @@ class StringIO
|
|
|
1170
1171
|
# strio.gets(nil) # "Slurp": read all.
|
|
1171
1172
|
# # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
1172
1173
|
#
|
|
1173
|
-
#
|
|
1174
|
+
# <strong>Keyword Argument `chomp`</strong>
|
|
1174
1175
|
#
|
|
1175
1176
|
# With keyword argument `chomp` given as `true` (the default is `false`),
|
|
1176
1177
|
# removes the trailing newline (if any) from the returned line:
|
|
@@ -1507,7 +1508,7 @@ class StringIO
|
|
|
1507
1508
|
# **No Arguments**
|
|
1508
1509
|
# With no arguments given,
|
|
1509
1510
|
# reads lines using the default record separator
|
|
1510
|
-
# (global variable
|
|
1511
|
+
# (global variable <code>$/</code>, whose initial value is <code>"\n"</code>).
|
|
1511
1512
|
# strio = StringIO.new(TEXT)
|
|
1512
1513
|
# strio.each_line {|line| p line }
|
|
1513
1514
|
# strio.eof? # => true
|
|
@@ -1519,7 +1520,7 @@ class StringIO
|
|
|
1519
1520
|
# "Fourth line\n"
|
|
1520
1521
|
# "Fifth line\n"
|
|
1521
1522
|
#
|
|
1522
|
-
#
|
|
1523
|
+
# <strong>Argument `sep`</strong>
|
|
1523
1524
|
# With only string argument `sep` given,
|
|
1524
1525
|
# reads lines using that string as the record separator:
|
|
1525
1526
|
# strio = StringIO.new(TEXT)
|
|
@@ -1532,7 +1533,7 @@ class StringIO
|
|
|
1532
1533
|
# "line\nFifth "
|
|
1533
1534
|
# "line\n"
|
|
1534
1535
|
#
|
|
1535
|
-
#
|
|
1536
|
+
# <strong>Argument `limit`</strong>
|
|
1536
1537
|
# With only integer argument `limit` given,
|
|
1537
1538
|
# reads lines using the default record separator;
|
|
1538
1539
|
# also limits the size (in characters) of each line to the given limit:
|
|
@@ -1550,7 +1551,7 @@ class StringIO
|
|
|
1550
1551
|
# "Fifth line"
|
|
1551
1552
|
# "\n"
|
|
1552
1553
|
#
|
|
1553
|
-
#
|
|
1554
|
+
# <strong>Arguments `sep` and `limit`</strong>
|
|
1554
1555
|
# With arguments `sep` and `limit` both given,
|
|
1555
1556
|
# honors both:
|
|
1556
1557
|
# strio = StringIO.new(TEXT)
|
|
@@ -1615,7 +1616,7 @@ class StringIO
|
|
|
1615
1616
|
# Output:
|
|
1616
1617
|
# "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
1617
1618
|
#
|
|
1618
|
-
#
|
|
1619
|
+
# <strong>Keyword Argument `chomp`</strong>
|
|
1619
1620
|
# With keyword argument `chomp` given as `true` (the default is `false`),
|
|
1620
1621
|
# removes trailing newline (if any) from each line:
|
|
1621
1622
|
# strio = StringIO.new(TEXT)
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# <!-- rdoc-file=ext/strscan/strscan.c -->
|
|
2
2
|
# Class `StringScanner` supports processing a stored string as a stream;
|
|
3
|
-
# this code creates a new `StringScanner` object with string
|
|
3
|
+
# this code creates a new `StringScanner` object with string
|
|
4
|
+
# <code>'foobarbaz'</code>:
|
|
4
5
|
# require 'strscan'
|
|
5
6
|
# scanner = StringScanner.new('foobarbaz')
|
|
6
7
|
#
|
|
@@ -19,13 +20,13 @@
|
|
|
19
20
|
# ENGLISH_TEXT = 'Hello'
|
|
20
21
|
#
|
|
21
22
|
# Some examples here assume that certain helper methods are defined:
|
|
22
|
-
# *
|
|
23
|
+
# * <code>put_situation(scanner)</code>:
|
|
23
24
|
# Displays the values of the scanner's
|
|
24
25
|
# methods #pos, #charpos, #rest, and #rest_size.
|
|
25
|
-
# *
|
|
26
|
+
# * <code>put_match_values(scanner)</code>:
|
|
26
27
|
# Displays the scanner's [match
|
|
27
28
|
# values](rdoc-ref:StringScanner@Match+Values).
|
|
28
|
-
# *
|
|
29
|
+
# * <code>match_values_cleared?(scanner)</code>:
|
|
29
30
|
# Returns whether the scanner's [match
|
|
30
31
|
# values](rdoc-ref:StringScanner@Match+Values) are cleared.
|
|
31
32
|
# See examples at [helper methods](helper_methods.md).
|
|
@@ -45,7 +46,7 @@
|
|
|
45
46
|
# The scanner has:
|
|
46
47
|
# * A *stored string*, which is:
|
|
47
48
|
# * Initially set by StringScanner.new(string) to the given `string`
|
|
48
|
-
# (
|
|
49
|
+
# (<code>'foobarbaz'</code> in the example above).
|
|
49
50
|
# * Modifiable by methods #string=(new_string) and #concat(more_string).
|
|
50
51
|
# * Returned by method #string.
|
|
51
52
|
# More at [Stored String](rdoc-ref:StringScanner@Stored+String) below.
|
|
@@ -63,7 +64,7 @@
|
|
|
63
64
|
# which is a trailing substring of the stored string;
|
|
64
65
|
# it extends from the current position to the end of the stored string:
|
|
65
66
|
# * Initially set by StringScanner.new(string) to the given `string`
|
|
66
|
-
# (
|
|
67
|
+
# (<code>'foobarbaz'</code> in the example above).
|
|
67
68
|
# * Returned by method #rest.
|
|
68
69
|
# * Modified by any modification to either the stored string or the
|
|
69
70
|
# position.
|
|
@@ -96,7 +97,7 @@
|
|
|
96
97
|
# When the byte position is:
|
|
97
98
|
# * Zero (at the beginning), the target substring is the entire stored string.
|
|
98
99
|
# * Equal to the size of the stored string (at the end),
|
|
99
|
-
# the target substring is the empty string
|
|
100
|
+
# the target substring is the empty string <code>''</code>.
|
|
100
101
|
# To get or set the byte position:
|
|
101
102
|
# * #pos: returns the byte position.
|
|
102
103
|
# * #pos=(new_pos): sets the byte position.
|
|
@@ -120,7 +121,7 @@
|
|
|
120
121
|
# * #charpos: the [character
|
|
121
122
|
# position](rdoc-ref:StringScanner@Character+Position).
|
|
122
123
|
# * #rest: the [target substring](rdoc-ref:StringScanner@Target+Substring).
|
|
123
|
-
# * #rest_size:
|
|
124
|
+
# * #rest_size: <code>rest.size</code>.
|
|
124
125
|
# ### Character Position
|
|
125
126
|
# The character position is a zero-based index into the *characters*
|
|
126
127
|
# in the stored string;
|
|
@@ -211,12 +212,12 @@
|
|
|
211
212
|
# This table summarizes (details and examples at the links):
|
|
212
213
|
# Method | Returns |Sets Match Values?
|
|
213
214
|
# ---------------------|---------------------------------------------|------------------
|
|
214
|
-
# #check(pattern) | Matched leading substring or
|
|
215
|
-
# #check_until(pattern)| Matched substring (anywhere) or
|
|
215
|
+
# #check(pattern) | Matched leading substring or +nil+. | Yes.
|
|
216
|
+
# #check_until(pattern)| Matched substring (anywhere) or +nil+. | Yes.
|
|
216
217
|
# #exist?(pattern) | Matched substring (anywhere) end index. | Yes.
|
|
217
|
-
# #match?(pattern) | Size of matched leading substring or
|
|
218
|
+
# #match?(pattern) | Size of matched leading substring or +nil+. | Yes.
|
|
218
219
|
# #peek(size) | Leading substring of given length (bytes). | No.
|
|
219
|
-
# #peek_byte | Integer leading byte or
|
|
220
|
+
# #peek_byte | Integer leading byte or +nil+. | No.
|
|
220
221
|
# #rest |Target substring (from byte position to end).| No.
|
|
221
222
|
# ### Traversing the Target Substring
|
|
222
223
|
# A *traversal* method examines the target substring,
|
|
@@ -226,24 +227,24 @@
|
|
|
226
227
|
# This table summarizes (details and examples at links):
|
|
227
228
|
# Method | Returns |Sets Match Values?
|
|
228
229
|
# --------------------|----------------------------------------------------|------------------
|
|
229
|
-
# #get_byte | Leading byte or
|
|
230
|
-
# #getch | Leading character or
|
|
231
|
-
# #scan(pattern) | Matched leading substring or
|
|
232
|
-
# #scan_byte | Integer leading byte or
|
|
233
|
-
# #scan_until(pattern)| Matched substring (anywhere) or
|
|
234
|
-
# #skip(pattern) | Matched leading substring size or
|
|
235
|
-
# #skip_until(pattern)|Position delta to end-of-matched-substring or
|
|
236
|
-
# #unscan |
|
|
230
|
+
# #get_byte | Leading byte or +nil+. | No.
|
|
231
|
+
# #getch | Leading character or +nil+. | No.
|
|
232
|
+
# #scan(pattern) | Matched leading substring or +nil+. | Yes.
|
|
233
|
+
# #scan_byte | Integer leading byte or +nil+. | No.
|
|
234
|
+
# #scan_until(pattern)| Matched substring (anywhere) or +nil+. | Yes.
|
|
235
|
+
# #skip(pattern) | Matched leading substring size or +nil+. | Yes.
|
|
236
|
+
# #skip_until(pattern)|Position delta to end-of-matched-substring or +nil+.| Yes.
|
|
237
|
+
# #unscan | +self+. | No.
|
|
237
238
|
# ## Querying the Scanner
|
|
238
239
|
# Each of these methods queries the scanner object
|
|
239
240
|
# without modifying it (details and examples at links)
|
|
240
241
|
# Method | Returns
|
|
241
242
|
# -------------------|--------------------------------
|
|
242
|
-
# #beginning_of_line?|
|
|
243
|
+
# #beginning_of_line?| +true+ or +false+.
|
|
243
244
|
# #charpos | Character position.
|
|
244
|
-
# #eos? |
|
|
245
|
-
# #fixed_anchor? |
|
|
246
|
-
# #inspect |String representation of
|
|
245
|
+
# #eos? | +true+ or +false+.
|
|
246
|
+
# #fixed_anchor? | +true+ or +false+.
|
|
247
|
+
# #inspect |String representation of +self+.
|
|
247
248
|
# #pos | Byte position.
|
|
248
249
|
# #rest | Target substring.
|
|
249
250
|
# #rest_size | Size of target substring.
|
|
@@ -290,7 +291,7 @@
|
|
|
290
291
|
# generally contain the results of the most recent attempted match.
|
|
291
292
|
# Each match value may be thought of as:
|
|
292
293
|
# * *Clear*: Initially, or after an unsuccessful match attempt:
|
|
293
|
-
# usually, `false`, `nil`, or
|
|
294
|
+
# usually, `false`, `nil`, or <code>{}</code>.
|
|
294
295
|
# * *Set*: After a successful match attempt:
|
|
295
296
|
# `true`, string, array, or hash.
|
|
296
297
|
# Each of these methods clears match values:
|
|
@@ -312,11 +313,11 @@
|
|
|
312
313
|
# Each of these methods returns a basic match value:
|
|
313
314
|
# Method | Return After Match |Return After No Match
|
|
314
315
|
# -------------|--------------------------------------|---------------------
|
|
315
|
-
# #matched? |
|
|
316
|
-
# #matched_size| Size of matched substring. |
|
|
317
|
-
# #matched | Matched substring. |
|
|
318
|
-
# #pre_match |Substring preceding matched substring.|
|
|
319
|
-
# #post_match |Substring following matched substring.|
|
|
316
|
+
# #matched? | +true+. | +false+.
|
|
317
|
+
# #matched_size| Size of matched substring. | +nil+.
|
|
318
|
+
# #matched | Matched substring. | +nil+.
|
|
319
|
+
# #pre_match |Substring preceding matched substring.| +nil+.
|
|
320
|
+
# #post_match |Substring following matched substring.| +nil+.
|
|
320
321
|
#
|
|
321
322
|
# See examples below.
|
|
322
323
|
# #### Captured Match Values
|
|
@@ -326,11 +327,11 @@
|
|
|
326
327
|
# Each of these methods returns a captured match value:
|
|
327
328
|
# Method | Return After Match |Return After No Match
|
|
328
329
|
# ---------------|---------------------------------------|---------------------
|
|
329
|
-
# #size | Count of captured substrings. |
|
|
330
|
-
# #[](n) | `n`th captured substring. |
|
|
331
|
-
# #captures | Array of all captured substrings. |
|
|
332
|
-
# #values_at(*n) |Array of specified captured substrings.|
|
|
333
|
-
# #named_captures| Hash of named captures. |
|
|
330
|
+
# #size | Count of captured substrings. | +nil+.
|
|
331
|
+
# #[](n) | `n`th captured substring. | +nil+.
|
|
332
|
+
# #captures | Array of all captured substrings. | +nil+.
|
|
333
|
+
# #values_at(*n) |Array of specified captured substrings.| +nil+.
|
|
334
|
+
# #named_captures| Hash of named captures. | <code>{}</code>.
|
|
334
335
|
#
|
|
335
336
|
# See examples below.
|
|
336
337
|
# #### Match Values Examples
|
|
@@ -401,7 +402,7 @@
|
|
|
401
402
|
# ## Fixed-Anchor Property
|
|
402
403
|
# Pattern matching in `StringScanner` is the same as in Ruby's,
|
|
403
404
|
# except for its fixed-anchor property,
|
|
404
|
-
# which determines the meaning of
|
|
405
|
+
# which determines the meaning of <code>'\A'</code>:
|
|
405
406
|
# * `false` (the default): matches the current byte position.
|
|
406
407
|
# scanner = StringScanner.new('foobar')
|
|
407
408
|
# scanner.scan(/\A./) # => "f"
|
|
@@ -486,13 +487,13 @@ class StringScanner
|
|
|
486
487
|
# scanner[:day] # => "12"
|
|
487
488
|
# scanner[:nope] # => nil
|
|
488
489
|
#
|
|
489
|
-
# When there are no captures, only
|
|
490
|
+
# When there are no captures, only <code>[0]</code> returns non-`nil`:
|
|
490
491
|
# scanner = StringScanner.new('foobarbaz')
|
|
491
492
|
# scanner.exist?(/bar/)
|
|
492
493
|
# scanner[0] # => "bar"
|
|
493
494
|
# scanner[1] # => nil
|
|
494
495
|
#
|
|
495
|
-
# For a failed match, even
|
|
496
|
+
# For a failed match, even <code>[0]</code> returns `nil`:
|
|
496
497
|
# scanner.scan(/nope/) # => nil
|
|
497
498
|
# scanner[0] # => nil
|
|
498
499
|
# scanner[1] # => nil
|
|
@@ -539,7 +540,8 @@ class StringScanner
|
|
|
539
540
|
# - captures -> substring_array or nil
|
|
540
541
|
# -->
|
|
541
542
|
# Returns the array of [captured match
|
|
542
|
-
# values](rdoc-ref:StringScanner@Captured+Match+Values) at indexes
|
|
543
|
+
# values](rdoc-ref:StringScanner@Captured+Match+Values) at indexes
|
|
544
|
+
# <code>(1..)</code>
|
|
543
545
|
# if the most recent match attempt succeeded, or `nil` otherwise:
|
|
544
546
|
# scanner = StringScanner.new('Fri Dec 12 1975 14:39')
|
|
545
547
|
# scanner.captures # => nil
|
|
@@ -999,7 +1001,7 @@ class StringScanner
|
|
|
999
1001
|
# rdoc-file=ext/strscan/strscan.c
|
|
1000
1002
|
# - peek(length) -> substring
|
|
1001
1003
|
# -->
|
|
1002
|
-
# Returns the substring
|
|
1004
|
+
# Returns the substring <code>string[pos, length]</code>;
|
|
1003
1005
|
# does not update [match values](rdoc-ref:StringScanner@Match+Values) or
|
|
1004
1006
|
# [positions](rdoc-ref:StringScanner@Positions):
|
|
1005
1007
|
# scanner = StringScanner.new('foobarbaz')
|
|
@@ -1151,7 +1153,7 @@ class StringScanner
|
|
|
1151
1153
|
# Sets both [byte position](rdoc-ref:StringScanner@Byte+Position+-28Position-29)
|
|
1152
1154
|
# and [character position](rdoc-ref:StringScanner@Character+Position) to zero,
|
|
1153
1155
|
# and clears [match values](rdoc-ref:StringScanner@Match+Values);
|
|
1154
|
-
# returns
|
|
1156
|
+
# returns +self+:
|
|
1155
1157
|
# scanner = StringScanner.new('foobarbaz')
|
|
1156
1158
|
# scanner.exist?(/bar/) # => 6
|
|
1157
1159
|
# scanner.reset # => #<StringScanner 0/9 @ "fooba...">
|
|
@@ -1237,7 +1239,7 @@ class StringScanner
|
|
|
1237
1239
|
# * Returns the matched substring.
|
|
1238
1240
|
# * Increments the [byte
|
|
1239
1241
|
# position](rdoc-ref:StringScanner@Byte+Position+-28Position-29) by
|
|
1240
|
-
#
|
|
1242
|
+
# <code>substring.bytesize</code>,
|
|
1241
1243
|
# and may increment the [character
|
|
1242
1244
|
# position](rdoc-ref:StringScanner@Character+Position).
|
|
1243
1245
|
# * Sets [match values](rdoc-ref:StringScanner@Match+Values).
|
|
@@ -1517,7 +1519,7 @@ class StringScanner
|
|
|
1517
1519
|
# call-seq:
|
|
1518
1520
|
# terminate -> self
|
|
1519
1521
|
# Sets the scanner to end-of-string;
|
|
1520
|
-
# returns
|
|
1522
|
+
# returns +self+:
|
|
1521
1523
|
# * Sets both [positions](rdoc-ref:StringScanner@Positions) to end-of-stream.
|
|
1522
1524
|
# * Clears [match values](rdoc-ref:StringScanner@Match+Values).
|
|
1523
1525
|
# scanner = StringScanner.new(HIRAGANA_TEXT)
|
|
@@ -1578,7 +1580,7 @@ class StringScanner
|
|
|
1578
1580
|
# - values_at(*specifiers) -> array_of_captures or nil
|
|
1579
1581
|
# -->
|
|
1580
1582
|
# Returns an array of captured substrings, or `nil` of none.
|
|
1581
|
-
# For each `specifier`, the returned substring is
|
|
1583
|
+
# For each `specifier`, the returned substring is <code>[specifier]</code>;
|
|
1582
1584
|
# see #[].
|
|
1583
1585
|
# scanner = StringScanner.new('Fri Dec 12 1975 14:39')
|
|
1584
1586
|
# pattern = /(?<wday>\w+) (?<month>\w+) (?<day>\d+) /
|
|
@@ -159,7 +159,7 @@ class Tempfile < File
|
|
|
159
159
|
# * Generated filename is unique in that directory.
|
|
160
160
|
# * Permissions are `0600`; see [File
|
|
161
161
|
# Permissions](rdoc-ref:File@File+Permissions).
|
|
162
|
-
# * Mode is
|
|
162
|
+
# * Mode is <code>'w+'</code> (read/write mode, positioned at the end).
|
|
163
163
|
#
|
|
164
164
|
# The temporary file removal depends on the keyword argument `anonymous` and
|
|
165
165
|
# whether a block is given or not. See the description about the `anonymous`
|
|
@@ -206,8 +206,8 @@ class Tempfile < File
|
|
|
206
206
|
#
|
|
207
207
|
# Tempfile.create('foo') # => #<File:/tmp/foo20220505-9795-1gok8l9>
|
|
208
208
|
#
|
|
209
|
-
# * An array of two strings
|
|
210
|
-
# with `prefix` and ends with `suffix`:
|
|
209
|
+
# * An array of two strings <code>[prefix, suffix]</code>: the generated
|
|
210
|
+
# filename begins with `prefix` and ends with `suffix`:
|
|
211
211
|
#
|
|
212
212
|
# Tempfile.create(%w/foo .jpg/) # => #<File:/tmp/foo20220505-17839-tnjchh.jpg>
|
|
213
213
|
#
|
|
@@ -226,16 +226,19 @@ class Tempfile < File
|
|
|
226
226
|
#
|
|
227
227
|
# The keyword argument `anonymous` specifies when the file is removed.
|
|
228
228
|
#
|
|
229
|
-
# *
|
|
230
|
-
#
|
|
231
|
-
#
|
|
232
|
-
#
|
|
233
|
-
# *
|
|
234
|
-
#
|
|
229
|
+
# * <code>anonymous=false</code> (default) without a block: the file is not
|
|
230
|
+
# removed.
|
|
231
|
+
# * <code>anonymous=false</code> (default) with a block: the file is removed
|
|
232
|
+
# after the block exits.
|
|
233
|
+
# * <code>anonymous=true</code> without a block: the file is removed before
|
|
234
|
+
# returning.
|
|
235
|
+
# * <code>anonymous=true</code> with a block: the file is removed before the
|
|
236
|
+
# block is called.
|
|
235
237
|
#
|
|
236
|
-
# In the first case (
|
|
237
|
-
# automatically. It should be explicitly closed. It can be used to
|
|
238
|
-
# desired filename. If the file is not needed, it should be
|
|
238
|
+
# In the first case (<code>anonymous=false</code> without a block), the file is
|
|
239
|
+
# not removed automatically. It should be explicitly closed. It can be used to
|
|
240
|
+
# rename to the desired filename. If the file is not needed, it should be
|
|
241
|
+
# explicitly removed.
|
|
239
242
|
#
|
|
240
243
|
# The File#path method of the created file object returns the temporary
|
|
241
244
|
# directory with a trailing slash when `anonymous` is true.
|
|
@@ -248,8 +251,8 @@ class Tempfile < File
|
|
|
248
251
|
#
|
|
249
252
|
# Implementation note:
|
|
250
253
|
#
|
|
251
|
-
# The keyword argument
|
|
252
|
-
# on Windows. `O_TMPFILE` is used on Linux.
|
|
254
|
+
# The keyword argument <code>anonymous=true</code> is implemented using
|
|
255
|
+
# `FILE_SHARE_DELETE` on Windows. `O_TMPFILE` is used on Linux.
|
|
253
256
|
#
|
|
254
257
|
# Related: Tempfile.new.
|
|
255
258
|
#
|
|
@@ -283,7 +286,8 @@ class Tempfile < File
|
|
|
283
286
|
#
|
|
284
287
|
# The call returns the value of the block.
|
|
285
288
|
#
|
|
286
|
-
# In any case, all arguments (
|
|
289
|
+
# In any case, all arguments (<code>*args</code>) will be passed to
|
|
290
|
+
# Tempfile.new.
|
|
287
291
|
#
|
|
288
292
|
# Tempfile.open('foo', '/home/temp') do |f|
|
|
289
293
|
# # ... do something with f ...
|
|
@@ -318,7 +322,7 @@ class Tempfile < File
|
|
|
318
322
|
# - close!()
|
|
319
323
|
# -->
|
|
320
324
|
# Closes and unlinks (deletes) the file. Has the same effect as called
|
|
321
|
-
#
|
|
325
|
+
# <code>close(true)</code>.
|
|
322
326
|
#
|
|
323
327
|
def close!: () -> void
|
|
324
328
|
|
|
@@ -422,7 +426,7 @@ class Tempfile < File
|
|
|
422
426
|
# If possible, consider instead using Tempfile.create, which:
|
|
423
427
|
#
|
|
424
428
|
# * Avoids the performance cost of delegation, incurred when Tempfile.new
|
|
425
|
-
# calls its superclass
|
|
429
|
+
# calls its superclass <code>DelegateClass(File)</code>.
|
|
426
430
|
# * Does not rely on a finalizer to close and unlink the file, which can be
|
|
427
431
|
# unreliable.
|
|
428
432
|
#
|
|
@@ -433,7 +437,7 @@ class Tempfile < File
|
|
|
433
437
|
# * Generated filename is unique in that directory.
|
|
434
438
|
# * Permissions are `0600`; see [File
|
|
435
439
|
# Permissions](rdoc-ref:File@File+Permissions).
|
|
436
|
-
# * Mode is
|
|
440
|
+
# * Mode is <code>'w+'</code> (read/write mode, positioned at the end).
|
|
437
441
|
#
|
|
438
442
|
# The underlying file is removed when the Tempfile object dies and is reclaimed
|
|
439
443
|
# by the garbage collector.
|
|
@@ -454,8 +458,8 @@ class Tempfile < File
|
|
|
454
458
|
#
|
|
455
459
|
# Tempfile.new('foo') # => #<Tempfile:/tmp/foo20220505-17839-1whk2f>
|
|
456
460
|
#
|
|
457
|
-
# * An array of two strings
|
|
458
|
-
# with `prefix` and ends with `suffix`:
|
|
461
|
+
# * An array of two strings <code>[prefix, suffix]</code>: the generated
|
|
462
|
+
# filename begins with `prefix` and ends with `suffix`:
|
|
459
463
|
#
|
|
460
464
|
# Tempfile.new(%w/foo .jpg/) # => #<Tempfile:/tmp/foo20220505-17839-58xtfi.jpg>
|
|
461
465
|
#
|