rbs 3.9.5 → 3.10.0.pre.1
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 +74 -0
- data/.clangd +2 -0
- data/.github/workflows/c-check.yml +54 -0
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +34 -19
- data/.github/workflows/typecheck.yml +1 -1
- data/.github/workflows/windows.yml +1 -1
- data/.gitignore +4 -0
- data/README.md +38 -1
- data/Rakefile +152 -23
- data/config.yml +190 -62
- data/core/array.rbs +44 -43
- data/core/dir.rbs +2 -2
- data/core/encoding.rbs +3 -2
- data/core/enumerable.rbs +89 -2
- data/core/errno.rbs +8 -0
- data/core/errors.rbs +28 -1
- data/core/exception.rbs +2 -2
- data/core/fiber.rbs +3 -3
- data/core/file.rbs +26 -11
- data/core/float.rbs +1 -1
- data/core/gc.rbs +422 -281
- data/core/hash.rbs +1024 -727
- data/core/io/wait.rbs +11 -33
- data/core/io.rbs +6 -4
- data/core/kernel.rbs +49 -43
- data/core/marshal.rbs +1 -1
- data/core/match_data.rbs +1 -1
- data/core/math.rbs +42 -3
- data/core/method.rbs +14 -6
- data/core/module.rbs +71 -11
- data/core/nil_class.rbs +3 -3
- data/core/numeric.rbs +8 -8
- data/core/object.rbs +3 -3
- data/core/object_space.rbs +13 -0
- data/{stdlib/pathname/0 → core}/pathname.rbs +253 -352
- data/core/proc.rbs +15 -8
- data/core/process.rbs +2 -2
- data/core/ractor.rbs +278 -437
- data/core/range.rbs +6 -7
- data/core/rbs/unnamed/argf.rbs +1 -1
- data/core/rbs/unnamed/env_class.rbs +1 -1
- data/core/rbs/unnamed/random.rbs +4 -2
- data/core/regexp.rbs +22 -17
- data/core/ruby_vm.rbs +6 -4
- data/core/rubygems/errors.rbs +3 -70
- data/core/rubygems/rubygems.rbs +11 -79
- data/core/set.rbs +439 -332
- data/core/string.rbs +2897 -1117
- data/core/struct.rbs +1 -1
- data/core/symbol.rbs +4 -4
- data/core/thread.rbs +83 -20
- data/core/time.rbs +35 -9
- data/core/unbound_method.rbs +14 -6
- data/docs/aliases.md +79 -0
- data/docs/collection.md +2 -2
- data/docs/gem.md +0 -1
- data/docs/sigs.md +3 -3
- data/ext/rbs_extension/ast_translation.c +1016 -0
- data/ext/rbs_extension/ast_translation.h +37 -0
- data/ext/rbs_extension/class_constants.c +157 -0
- data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
- data/ext/rbs_extension/compat.h +10 -0
- data/ext/rbs_extension/extconf.rb +25 -1
- data/ext/rbs_extension/legacy_location.c +317 -0
- data/ext/rbs_extension/legacy_location.h +45 -0
- data/ext/rbs_extension/main.c +365 -14
- data/ext/rbs_extension/rbs_extension.h +6 -21
- data/ext/rbs_extension/rbs_string_bridging.c +9 -0
- data/ext/rbs_extension/rbs_string_bridging.h +24 -0
- data/include/rbs/ast.h +687 -0
- data/include/rbs/defines.h +86 -0
- data/include/rbs/lexer.h +199 -0
- data/include/rbs/location.h +59 -0
- data/include/rbs/parser.h +135 -0
- data/include/rbs/string.h +49 -0
- data/include/rbs/util/rbs_allocator.h +59 -0
- data/include/rbs/util/rbs_assert.h +20 -0
- data/include/rbs/util/rbs_buffer.h +83 -0
- data/include/rbs/util/rbs_constant_pool.h +6 -67
- data/include/rbs/util/rbs_encoding.h +282 -0
- data/include/rbs/util/rbs_unescape.h +23 -0
- data/include/rbs.h +1 -2
- data/lib/rbs/annotate/formatter.rb +3 -13
- data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
- data/lib/rbs/annotate/rdoc_source.rb +1 -1
- data/lib/rbs/cli/validate.rb +2 -2
- data/lib/rbs/cli.rb +1 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
- data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
- data/lib/rbs/environment.rb +64 -59
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/errors.rb +1 -1
- data/lib/rbs/parser_aux.rb +5 -0
- data/lib/rbs/resolver/constant_resolver.rb +2 -2
- data/lib/rbs/resolver/type_name_resolver.rb +124 -38
- data/lib/rbs/test/type_check.rb +13 -0
- data/lib/rbs/types.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rbs.rb +1 -1
- data/lib/rdoc/discover.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +3 -3
- data/sig/annotate/formatter.rbs +2 -2
- data/sig/annotate/rdoc_annotater.rbs +1 -1
- data/sig/environment.rbs +57 -6
- data/sig/manifest.yaml +0 -1
- data/sig/parser.rbs +20 -0
- data/sig/resolver/type_name_resolver.rbs +38 -7
- data/sig/types.rbs +4 -1
- data/src/ast.c +1256 -0
- data/src/lexer.c +2956 -0
- data/src/lexer.re +147 -0
- data/src/lexstate.c +205 -0
- data/src/location.c +71 -0
- data/src/parser.c +3495 -0
- data/src/string.c +90 -0
- data/src/util/rbs_allocator.c +152 -0
- data/src/util/rbs_assert.c +21 -0
- data/src/util/rbs_buffer.c +54 -0
- data/src/util/rbs_constant_pool.c +16 -86
- data/src/util/rbs_encoding.c +21308 -0
- data/src/util/rbs_unescape.c +131 -0
- data/stdlib/cgi/0/core.rbs +2 -396
- data/stdlib/cgi/0/manifest.yaml +1 -0
- data/stdlib/cgi-escape/0/escape.rbs +153 -0
- data/stdlib/coverage/0/coverage.rbs +3 -1
- data/stdlib/delegate/0/delegator.rbs +10 -7
- data/stdlib/erb/0/erb.rbs +737 -347
- data/stdlib/fileutils/0/fileutils.rbs +18 -13
- data/stdlib/forwardable/0/forwardable.rbs +3 -0
- data/stdlib/json/0/json.rbs +67 -48
- data/stdlib/net-http/0/net-http.rbs +3 -0
- data/stdlib/objspace/0/objspace.rbs +8 -3
- data/stdlib/open-uri/0/open-uri.rbs +40 -0
- data/stdlib/openssl/0/openssl.rbs +182 -149
- data/stdlib/optparse/0/optparse.rbs +3 -3
- data/stdlib/rdoc/0/code_object.rbs +2 -2
- data/stdlib/rdoc/0/comment.rbs +2 -0
- data/stdlib/rdoc/0/options.rbs +76 -0
- data/stdlib/rdoc/0/rdoc.rbs +7 -5
- data/stdlib/rdoc/0/store.rbs +1 -1
- data/stdlib/resolv/0/resolv.rbs +25 -68
- data/stdlib/ripper/0/ripper.rbs +5 -2
- data/stdlib/singleton/0/singleton.rbs +3 -0
- data/stdlib/socket/0/socket.rbs +13 -1
- data/stdlib/socket/0/tcp_socket.rbs +10 -2
- data/stdlib/stringio/0/stringio.rbs +412 -80
- data/stdlib/strscan/0/string_scanner.rbs +31 -31
- data/stdlib/tempfile/0/tempfile.rbs +1 -1
- data/stdlib/tsort/0/cyclic.rbs +3 -0
- data/stdlib/uri/0/common.rbs +11 -2
- data/stdlib/uri/0/file.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +16 -15
- data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
- data/stdlib/zlib/0/zstream.rbs +1 -0
- metadata +41 -18
- data/ext/rbs_extension/lexer.c +0 -2728
- data/ext/rbs_extension/lexer.h +0 -179
- data/ext/rbs_extension/lexer.re +0 -147
- data/ext/rbs_extension/lexstate.c +0 -175
- data/ext/rbs_extension/location.c +0 -325
- data/ext/rbs_extension/location.h +0 -85
- data/ext/rbs_extension/parser.c +0 -2982
- data/ext/rbs_extension/parser.h +0 -18
- data/ext/rbs_extension/parserstate.c +0 -411
- data/ext/rbs_extension/parserstate.h +0 -163
- data/ext/rbs_extension/unescape.c +0 -32
- data/include/rbs/ruby_objs.h +0 -72
- data/src/constants.c +0 -153
- data/src/ruby_objs.c +0 -799
|
@@ -1,50 +1,71 @@
|
|
|
1
1
|
# <!-- rdoc-file=ext/stringio/stringio.c -->
|
|
2
|
-
# IO streams for strings, with access similar to
|
|
3
|
-
# [IO](rdoc-ref:IO)
|
|
4
|
-
#
|
|
2
|
+
# IO streams for strings, with access similar to
|
|
3
|
+
# [IO](rdoc-ref:IO);
|
|
4
|
+
# see [IO](rdoc-ref:IO).
|
|
5
5
|
# ### About the Examples
|
|
6
|
-
#
|
|
7
6
|
# Examples on this page assume that StringIO has been required:
|
|
8
|
-
#
|
|
9
7
|
# require 'stringio'
|
|
10
8
|
#
|
|
9
|
+
# And that these constants have been defined:
|
|
10
|
+
# TEXT = <<EOT
|
|
11
|
+
# First line
|
|
12
|
+
# Second line
|
|
13
|
+
#
|
|
14
|
+
# Fourth line
|
|
15
|
+
# Fifth line
|
|
16
|
+
# EOT
|
|
17
|
+
#
|
|
18
|
+
# RUSSIAN = 'тест'
|
|
19
|
+
# DATA = "\u9990\u9991\u9992\u9993\u9994"
|
|
20
|
+
#
|
|
11
21
|
class StringIO
|
|
12
22
|
# <!--
|
|
13
23
|
# rdoc-file=ext/stringio/stringio.c
|
|
14
24
|
# - StringIO.new(string = '', mode = 'r+') -> new_stringio
|
|
15
25
|
# -->
|
|
16
|
-
#
|
|
26
|
+
# Returns a new StringIO instance formed from `string` and `mode`; the instance
|
|
27
|
+
# should be closed when no longer needed:
|
|
17
28
|
#
|
|
18
|
-
#
|
|
19
|
-
#
|
|
29
|
+
# strio = StringIO.new
|
|
30
|
+
# strio.string # => ""
|
|
31
|
+
# strio.closed_read? # => false
|
|
32
|
+
# strio.closed_write? # => false
|
|
33
|
+
# strio.close
|
|
34
|
+
#
|
|
35
|
+
# If `string` is frozen, the default `mode` is `'r'`:
|
|
20
36
|
#
|
|
21
|
-
# strio = StringIO.new
|
|
37
|
+
# strio = StringIO.new('foo'.freeze)
|
|
38
|
+
# strio.string # => "foo"
|
|
39
|
+
# strio.closed_read? # => false
|
|
40
|
+
# strio.closed_write? # => true
|
|
22
41
|
# strio.close
|
|
23
42
|
#
|
|
24
|
-
#
|
|
43
|
+
# Argument `mode` must be a valid [Access Mode](rdoc-ref:File@Access+Modes),
|
|
44
|
+
# which may be a string or an integer constant:
|
|
45
|
+
#
|
|
46
|
+
# StringIO.new('foo', 'w+')
|
|
47
|
+
# StringIO.new('foo', File::RDONLY)
|
|
25
48
|
#
|
|
26
|
-
# Related: StringIO.open (
|
|
49
|
+
# Related: StringIO.open (passes the StringIO object to the block; closes the
|
|
50
|
+
# object automatically on block exit).
|
|
27
51
|
#
|
|
28
52
|
def initialize: (?String string, ?String? mode) -> void
|
|
29
53
|
|
|
30
54
|
# <!--
|
|
31
55
|
# rdoc-file=ext/stringio/stringio.c
|
|
32
|
-
# - StringIO.open(string = '', mode = 'r+')
|
|
56
|
+
# - StringIO.open(string = '', mode = 'r+') -> new_stringio
|
|
57
|
+
# - StringIO.open(string = '', mode = 'r+') {|strio| ... } -> object
|
|
33
58
|
# -->
|
|
34
|
-
#
|
|
59
|
+
# Creates new StringIO instance by calling `StringIO.new(string, mode)`.
|
|
35
60
|
#
|
|
36
|
-
#
|
|
37
|
-
# Modes](rdoc-ref:File@Access+Modes).
|
|
38
|
-
#
|
|
39
|
-
# With no block, returns the new instance:
|
|
61
|
+
# With no block given, returns the new instance:
|
|
40
62
|
#
|
|
41
63
|
# strio = StringIO.open # => #<StringIO>
|
|
42
64
|
#
|
|
43
|
-
# With a block, calls the block with the new instance and returns the
|
|
44
|
-
# value; closes the instance on block exit
|
|
65
|
+
# With a block given, calls the block with the new instance and returns the
|
|
66
|
+
# block's value; closes the instance on block exit:
|
|
45
67
|
#
|
|
46
|
-
# StringIO.open {|strio|
|
|
47
|
-
# # => #<StringIO>
|
|
68
|
+
# StringIO.open('foo') {|strio| strio.string.upcase } # => "FOO"
|
|
48
69
|
#
|
|
49
70
|
# Related: StringIO.new.
|
|
50
71
|
#
|
|
@@ -65,11 +86,16 @@ class StringIO
|
|
|
65
86
|
# rdoc-file=ext/stringio/stringio.c
|
|
66
87
|
# - close -> nil
|
|
67
88
|
# -->
|
|
68
|
-
# Closes `self` for both reading and writing
|
|
89
|
+
# Closes `self` for both reading and writing; returns `nil`:
|
|
69
90
|
#
|
|
70
|
-
#
|
|
91
|
+
# strio = StringIO.new
|
|
92
|
+
# strio.closed? # => false
|
|
93
|
+
# strio.close # => nil
|
|
94
|
+
# strio.closed? # => true
|
|
95
|
+
# strio.read # Raises IOError: not opened for reading
|
|
96
|
+
# strio.write # Raises IOError: not opened for writing
|
|
71
97
|
#
|
|
72
|
-
# Related: StringIO#close_read, StringIO#close_write.
|
|
98
|
+
# Related: StringIO#close_read, StringIO#close_write, StringIO.closed?.
|
|
73
99
|
#
|
|
74
100
|
def close: () -> nil
|
|
75
101
|
|
|
@@ -77,9 +103,15 @@ class StringIO
|
|
|
77
103
|
# rdoc-file=ext/stringio/stringio.c
|
|
78
104
|
# - close_read -> nil
|
|
79
105
|
# -->
|
|
80
|
-
# Closes `self` for reading; closed-write setting remains unchanged
|
|
106
|
+
# Closes `self` for reading; closed-write setting remains unchanged; returns
|
|
107
|
+
# `nil`:
|
|
81
108
|
#
|
|
82
|
-
#
|
|
109
|
+
# strio = StringIO.new
|
|
110
|
+
# strio.closed_read? # => false
|
|
111
|
+
# strio.close_read # => nil
|
|
112
|
+
# strio.closed_read? # => true
|
|
113
|
+
# strio.closed_write? # => false
|
|
114
|
+
# strio.read # Raises IOError: not opened for reading
|
|
83
115
|
#
|
|
84
116
|
# Related: StringIO#close, StringIO#close_write.
|
|
85
117
|
#
|
|
@@ -89,11 +121,17 @@ class StringIO
|
|
|
89
121
|
# rdoc-file=ext/stringio/stringio.c
|
|
90
122
|
# - close_write -> nil
|
|
91
123
|
# -->
|
|
92
|
-
# Closes `self` for writing; closed-read setting remains unchanged
|
|
124
|
+
# Closes `self` for writing; closed-read setting remains unchanged; returns
|
|
125
|
+
# `nil`:
|
|
93
126
|
#
|
|
94
|
-
#
|
|
127
|
+
# strio = StringIO.new
|
|
128
|
+
# strio.closed_write? # => false
|
|
129
|
+
# strio.close_write # => nil
|
|
130
|
+
# strio.closed_write? # => true
|
|
131
|
+
# strio.closed_read? # => false
|
|
132
|
+
# strio.write('foo') # Raises IOError: not opened for writing
|
|
95
133
|
#
|
|
96
|
-
# Related: StringIO#close, StringIO#close_read
|
|
134
|
+
# Related: StringIO#close, StringIO#close_read, StringIO#closed_write?.
|
|
97
135
|
#
|
|
98
136
|
def close_write: () -> nil
|
|
99
137
|
|
|
@@ -101,8 +139,16 @@ class StringIO
|
|
|
101
139
|
# rdoc-file=ext/stringio/stringio.c
|
|
102
140
|
# - closed? -> true or false
|
|
103
141
|
# -->
|
|
104
|
-
# Returns
|
|
105
|
-
#
|
|
142
|
+
# Returns whether `self` is closed for both reading and writing:
|
|
143
|
+
#
|
|
144
|
+
# strio = StringIO.new
|
|
145
|
+
# strio.closed? # => false # Open for reading and writing.
|
|
146
|
+
# strio.close_read
|
|
147
|
+
# strio.closed? # => false # Still open for writing.
|
|
148
|
+
# strio.close_write
|
|
149
|
+
# strio.closed? # => true # Now closed for both.
|
|
150
|
+
#
|
|
151
|
+
# Related: StringIO.closed_read?, StringIO.closed_write?.
|
|
106
152
|
#
|
|
107
153
|
def closed?: () -> bool
|
|
108
154
|
|
|
@@ -110,7 +156,14 @@ class StringIO
|
|
|
110
156
|
# rdoc-file=ext/stringio/stringio.c
|
|
111
157
|
# - closed_read? -> true or false
|
|
112
158
|
# -->
|
|
113
|
-
# Returns
|
|
159
|
+
# Returns whether `self` is closed for reading:
|
|
160
|
+
#
|
|
161
|
+
# strio = StringIO.new
|
|
162
|
+
# strio.closed_read? # => false
|
|
163
|
+
# strio.close_read
|
|
164
|
+
# strio.closed_read? # => true
|
|
165
|
+
#
|
|
166
|
+
# Related: StringIO#closed?, StringIO#closed_write?, StringIO#close_read.
|
|
114
167
|
#
|
|
115
168
|
def closed_read?: () -> bool
|
|
116
169
|
|
|
@@ -118,7 +171,14 @@ class StringIO
|
|
|
118
171
|
# rdoc-file=ext/stringio/stringio.c
|
|
119
172
|
# - closed_write? -> true or false
|
|
120
173
|
# -->
|
|
121
|
-
# Returns
|
|
174
|
+
# Returns whether `self` is closed for writing:
|
|
175
|
+
#
|
|
176
|
+
# strio = StringIO.new
|
|
177
|
+
# strio.closed_write? # => false
|
|
178
|
+
# strio.close_write
|
|
179
|
+
# strio.closed_write? # => true
|
|
180
|
+
#
|
|
181
|
+
# Related: StringIO#close_write, StringIO#closed?, StringIO#closed_read?.
|
|
122
182
|
#
|
|
123
183
|
def closed_write?: () -> bool
|
|
124
184
|
|
|
@@ -128,8 +188,6 @@ class StringIO
|
|
|
128
188
|
# - each_line(limit, chomp: false) {|line| ... } -> self
|
|
129
189
|
# - each_line(sep, limit, chomp: false) {|line| ... } -> self
|
|
130
190
|
# -->
|
|
131
|
-
# Calls the block with each remaining line read from the stream; does nothing if
|
|
132
|
-
# already at end-of-file; returns `self`. See [Line IO](rdoc-ref:IO@Line+IO).
|
|
133
191
|
#
|
|
134
192
|
def each: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self
|
|
135
193
|
| (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self]
|
|
@@ -139,21 +197,83 @@ class StringIO
|
|
|
139
197
|
# - each_byte {|byte| ... } -> self
|
|
140
198
|
# -->
|
|
141
199
|
# With a block given, calls the block with each remaining byte in the stream;
|
|
142
|
-
#
|
|
200
|
+
# positions the stream at end-of-file; returns `self`:
|
|
201
|
+
#
|
|
202
|
+
# bytes = []
|
|
203
|
+
# strio = StringIO.new('hello') # Five 1-byte characters.
|
|
204
|
+
# strio.each_byte {|byte| bytes.push(byte) }
|
|
205
|
+
# strio.eof? # => true
|
|
206
|
+
# bytes # => [104, 101, 108, 108, 111]
|
|
207
|
+
# bytes = []
|
|
208
|
+
# strio = StringIO.new('тест') # Four 2-byte characters.
|
|
209
|
+
# strio.each_byte {|byte| bytes.push(byte) }
|
|
210
|
+
# bytes # => [209, 130, 208, 181, 209, 129, 209, 130]
|
|
211
|
+
# bytes = []
|
|
212
|
+
# strio = StringIO.new('こんにちは') # Five 3-byte characters.
|
|
213
|
+
# strio.each_byte {|byte| bytes.push(byte) }
|
|
214
|
+
# bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
|
|
215
|
+
#
|
|
216
|
+
# The position in the stream matters:
|
|
143
217
|
#
|
|
144
|
-
#
|
|
218
|
+
# bytes = []
|
|
219
|
+
# strio = StringIO.new('こんにちは')
|
|
220
|
+
# strio.getc # => "こ"
|
|
221
|
+
# strio.pos # => 3 # 3-byte character was read.
|
|
222
|
+
# strio.each_byte {|byte| bytes.push(byte) }
|
|
223
|
+
# bytes # => [227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
|
|
224
|
+
#
|
|
225
|
+
# If at end-of-file, does not call the block:
|
|
226
|
+
#
|
|
227
|
+
# strio.eof? # => true
|
|
228
|
+
# strio.each_byte {|byte| fail 'Boo!' }
|
|
229
|
+
# strio.eof? # => true
|
|
230
|
+
#
|
|
231
|
+
# With no block given, returns a new [Enumerator](rdoc-ref:Enumerator).
|
|
232
|
+
#
|
|
233
|
+
# Related: StringIO#each_char, StringIO#each_codepoint, StringIO#each_line.
|
|
145
234
|
#
|
|
146
235
|
def each_byte: () { (Integer arg0) -> untyped } -> self
|
|
147
236
|
| () -> ::Enumerator[Integer, self]
|
|
148
237
|
|
|
149
238
|
# <!--
|
|
150
239
|
# rdoc-file=ext/stringio/stringio.c
|
|
151
|
-
# - each_char {|
|
|
240
|
+
# - each_char {|char| ... } -> self
|
|
152
241
|
# -->
|
|
153
242
|
# With a block given, calls the block with each remaining character in the
|
|
154
|
-
# stream;
|
|
243
|
+
# stream; positions the stream at end-of-file; returns `self`:
|
|
244
|
+
#
|
|
245
|
+
# chars = []
|
|
246
|
+
# strio = StringIO.new('hello')
|
|
247
|
+
# strio.each_char {|char| chars.push(char) }
|
|
248
|
+
# strio.eof? # => true
|
|
249
|
+
# chars # => ["h", "e", "l", "l", "o"]
|
|
250
|
+
# chars = []
|
|
251
|
+
# strio = StringIO.new('тест')
|
|
252
|
+
# strio.each_char {|char| chars.push(char) }
|
|
253
|
+
# chars # => ["т", "е", "с", "т"]
|
|
254
|
+
# chars = []
|
|
255
|
+
# strio = StringIO.new('こんにちは')
|
|
256
|
+
# strio.each_char {|char| chars.push(char) }
|
|
257
|
+
# chars # => ["こ", "ん", "に", "ち", "は"]
|
|
155
258
|
#
|
|
156
|
-
#
|
|
259
|
+
# Stream position matters:
|
|
260
|
+
#
|
|
261
|
+
# chars = []
|
|
262
|
+
# strio = StringIO.new('こんにちは')
|
|
263
|
+
# strio.getc # => "こ"
|
|
264
|
+
# strio.pos # => 3 # 3-byte character was read.
|
|
265
|
+
# strio.each_char {|char| chars.push(char) }
|
|
266
|
+
# chars # => ["ん", "に", "ち", "は"]
|
|
267
|
+
#
|
|
268
|
+
# When at end-of-stream does not call the block:
|
|
269
|
+
#
|
|
270
|
+
# strio.eof? # => true
|
|
271
|
+
# strio.each_char {|char| fail 'Boo!' }
|
|
272
|
+
# strio.eof? # => true
|
|
273
|
+
#
|
|
274
|
+
# With no block given, returns a new [Enumerator](rdoc-ref:Enumerator).
|
|
275
|
+
#
|
|
276
|
+
# Related: StringIO#each_byte, StringIO#each_codepoint, StringIO#each_line.
|
|
157
277
|
#
|
|
158
278
|
def each_char: () { (String arg0) -> untyped } -> self
|
|
159
279
|
| () -> ::Enumerator[String, self]
|
|
@@ -162,10 +282,43 @@ class StringIO
|
|
|
162
282
|
# rdoc-file=ext/stringio/stringio.c
|
|
163
283
|
# - each_codepoint {|codepoint| ... } -> self
|
|
164
284
|
# -->
|
|
165
|
-
# With a block given, calls the block with each
|
|
166
|
-
# stream;
|
|
285
|
+
# With a block given, calls the block with each successive codepoint from self;
|
|
286
|
+
# sets the position to end-of-stream; returns `self`.
|
|
287
|
+
#
|
|
288
|
+
# Each codepoint is the integer value for a character; returns self:
|
|
289
|
+
#
|
|
290
|
+
# codepoints = []
|
|
291
|
+
# strio = StringIO.new('hello')
|
|
292
|
+
# strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
|
|
293
|
+
# strio.eof? # => true
|
|
294
|
+
# codepoints # => [104, 101, 108, 108, 111]
|
|
295
|
+
# codepoints = []
|
|
296
|
+
# strio = StringIO.new('тест')
|
|
297
|
+
# strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
|
|
298
|
+
# codepoints # => [1090, 1077, 1089, 1090]
|
|
299
|
+
# codepoints = []
|
|
300
|
+
# strio = StringIO.new('こんにちは')
|
|
301
|
+
# strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
|
|
302
|
+
# codepoints # => [12371, 12435, 12395, 12385, 12399]
|
|
303
|
+
#
|
|
304
|
+
# Position in the stream matters:
|
|
305
|
+
#
|
|
306
|
+
# codepoints = []
|
|
307
|
+
# strio = StringIO.new('こんにちは')
|
|
308
|
+
# strio.getc # => "こ"
|
|
309
|
+
# strio.pos # => 3
|
|
310
|
+
# strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
|
|
311
|
+
# codepoints # => [12435, 12395, 12385, 12399]
|
|
312
|
+
#
|
|
313
|
+
# When at end-of-stream, the block is not called:
|
|
314
|
+
#
|
|
315
|
+
# strio.eof? # => true
|
|
316
|
+
# strio.each_codepoint {|codepoint| fail 'Boo!' }
|
|
317
|
+
# strio.eof? # => true
|
|
167
318
|
#
|
|
168
|
-
# With no block given, returns
|
|
319
|
+
# With no block given, returns a new [Enumerator](rdoc-ref:Enumerator).
|
|
320
|
+
#
|
|
321
|
+
# Related: StringIO#each_byte, StringIO#each_char, StringIO#each_line.
|
|
169
322
|
#
|
|
170
323
|
def each_codepoint: () { (Integer arg0) -> untyped } -> self
|
|
171
324
|
| () -> ::Enumerator[Integer, self]
|
|
@@ -174,10 +327,18 @@ class StringIO
|
|
|
174
327
|
# rdoc-file=ext/stringio/stringio.c
|
|
175
328
|
# - eof? -> true or false
|
|
176
329
|
# -->
|
|
177
|
-
# Returns `
|
|
178
|
-
#
|
|
330
|
+
# Returns whether `self` is positioned at end-of-stream:
|
|
331
|
+
#
|
|
332
|
+
# strio = StringIO.new('foo')
|
|
333
|
+
# strio.pos # => 0
|
|
334
|
+
# strio.eof? # => false
|
|
335
|
+
# strio.read # => "foo"
|
|
336
|
+
# strio.pos # => 3
|
|
337
|
+
# strio.eof? # => true
|
|
338
|
+
# strio.close_read
|
|
339
|
+
# strio.eof? # Raises IOError: not opened for reading
|
|
179
340
|
#
|
|
180
|
-
#
|
|
341
|
+
# Related: StringIO#pos.
|
|
181
342
|
#
|
|
182
343
|
def eof: () -> bool
|
|
183
344
|
|
|
@@ -193,7 +354,7 @@ class StringIO
|
|
|
193
354
|
# rdoc-file=ext/stringio/stringio.c
|
|
194
355
|
# - fileno()
|
|
195
356
|
# -->
|
|
196
|
-
# Returns `nil
|
|
357
|
+
# Returns `nil`; for compatibility with IO.
|
|
197
358
|
#
|
|
198
359
|
def fileno: () -> nil
|
|
199
360
|
|
|
@@ -201,7 +362,7 @@ class StringIO
|
|
|
201
362
|
# rdoc-file=ext/stringio/stringio.c
|
|
202
363
|
# - flush()
|
|
203
364
|
# -->
|
|
204
|
-
# Returns
|
|
365
|
+
# Returns `self`; for compatibility with IO.
|
|
205
366
|
#
|
|
206
367
|
def flush: () -> self
|
|
207
368
|
|
|
@@ -209,25 +370,84 @@ class StringIO
|
|
|
209
370
|
# rdoc-file=ext/stringio/stringio.c
|
|
210
371
|
# - fsync()
|
|
211
372
|
# -->
|
|
212
|
-
# Returns 0
|
|
373
|
+
# Returns 0; for compatibility with IO.
|
|
213
374
|
#
|
|
214
375
|
def fsync: () -> Integer?
|
|
215
376
|
|
|
216
377
|
# <!--
|
|
217
378
|
# rdoc-file=ext/stringio/stringio.c
|
|
218
|
-
# - getbyte ->
|
|
379
|
+
# - getbyte -> integer or nil
|
|
219
380
|
# -->
|
|
220
|
-
# Reads and returns the next
|
|
221
|
-
#
|
|
381
|
+
# Reads and returns the next integer byte (not character) from the stream:
|
|
382
|
+
#
|
|
383
|
+
# s = 'foo'
|
|
384
|
+
# s.bytes # => [102, 111, 111]
|
|
385
|
+
# strio = StringIO.new(s)
|
|
386
|
+
# strio.getbyte # => 102
|
|
387
|
+
# strio.getbyte # => 111
|
|
388
|
+
# strio.getbyte # => 111
|
|
389
|
+
#
|
|
390
|
+
# Returns `nil` if at end-of-stream:
|
|
391
|
+
#
|
|
392
|
+
# strio.eof? # => true
|
|
393
|
+
# strio.getbyte # => nil
|
|
394
|
+
#
|
|
395
|
+
# Returns a byte, not a character:
|
|
396
|
+
#
|
|
397
|
+
# s = 'тест'
|
|
398
|
+
# s.bytes # => [209, 130, 208, 181, 209, 129, 209, 130]
|
|
399
|
+
# strio = StringIO.new(s)
|
|
400
|
+
# strio.getbyte # => 209
|
|
401
|
+
# strio.getbyte # => 130
|
|
402
|
+
#
|
|
403
|
+
# s = 'こんにちは'
|
|
404
|
+
# s.bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
|
|
405
|
+
# strio = StringIO.new(s)
|
|
406
|
+
# strio.getbyte # => 227
|
|
407
|
+
# strio.getbyte # => 129
|
|
408
|
+
#
|
|
409
|
+
# Related: StringIO.getc.
|
|
222
410
|
#
|
|
223
411
|
def getbyte: () -> Integer?
|
|
224
412
|
|
|
225
413
|
# <!--
|
|
226
414
|
# rdoc-file=ext/stringio/stringio.c
|
|
227
|
-
# - getc -> character or nil
|
|
415
|
+
# - getc -> character, byte, or nil
|
|
228
416
|
# -->
|
|
229
|
-
# Reads and returns the next character from the stream
|
|
230
|
-
#
|
|
417
|
+
# Reads and returns the next character (or byte; see below) from the stream:
|
|
418
|
+
#
|
|
419
|
+
# strio = StringIO.new('foo')
|
|
420
|
+
# strio.getc # => "f"
|
|
421
|
+
# strio.getc # => "o"
|
|
422
|
+
# strio.getc # => "o"
|
|
423
|
+
#
|
|
424
|
+
# Returns `nil` if at end-of-stream:
|
|
425
|
+
#
|
|
426
|
+
# strio.eof? # => true
|
|
427
|
+
# strio.getc # => nil
|
|
428
|
+
#
|
|
429
|
+
# Returns characters, not bytes:
|
|
430
|
+
#
|
|
431
|
+
# strio = StringIO.new('тест')
|
|
432
|
+
# strio.getc # => "т"
|
|
433
|
+
# strio.getc # => "е"
|
|
434
|
+
#
|
|
435
|
+
# strio = StringIO.new('こんにちは')
|
|
436
|
+
# strio.getc # => "こ"
|
|
437
|
+
# strio.getc # => "ん"
|
|
438
|
+
#
|
|
439
|
+
# In each of the examples above, the stream is positioned at the beginning of a
|
|
440
|
+
# character; in other cases that need not be true:
|
|
441
|
+
#
|
|
442
|
+
# strio = StringIO.new('こんにちは') # Five 3-byte characters.
|
|
443
|
+
# strio.pos = 3 # => 3 # At beginning of second character; returns character.
|
|
444
|
+
# strio.getc # => "ん"
|
|
445
|
+
# strio.pos = 4 # => 4 # At second byte of second character; returns byte.
|
|
446
|
+
# strio.getc # => "\x82"
|
|
447
|
+
# strio.pos = 5 # => 5 # At third byte of second character; returns byte.
|
|
448
|
+
# strio.getc # => "\x93"
|
|
449
|
+
#
|
|
450
|
+
# Related: StringIO.getbyte.
|
|
231
451
|
#
|
|
232
452
|
def getc: () -> String?
|
|
233
453
|
|
|
@@ -237,26 +457,131 @@ class StringIO
|
|
|
237
457
|
# - gets(limit, chomp: false) -> string or nil
|
|
238
458
|
# - gets(sep, limit, chomp: false) -> string or nil
|
|
239
459
|
# -->
|
|
240
|
-
# Reads and returns a line from the stream;
|
|
241
|
-
#
|
|
460
|
+
# Reads and returns a line from the stream; returns `nil` if at end-of-stream.
|
|
461
|
+
#
|
|
462
|
+
# Side effects:
|
|
463
|
+
#
|
|
464
|
+
# * Increments stream position by the number of bytes read.
|
|
465
|
+
# * Assigns the return value to global variable `$_`.
|
|
466
|
+
#
|
|
467
|
+
# With no arguments given, reads a line using the default record separator
|
|
468
|
+
# (global variable `$/`,* whose initial value is `"\n"`):
|
|
469
|
+
#
|
|
470
|
+
# strio = StringIO.new(TEXT)
|
|
471
|
+
# strio.pos # => 0
|
|
472
|
+
# strio.gets # => "First line\n"
|
|
473
|
+
# strio.pos # => 11
|
|
474
|
+
# $_ # => "First line\n"
|
|
475
|
+
# strio.gets # => "Second line\n"
|
|
476
|
+
# strio.read # => "\nFourth line\nFifth line\n"
|
|
477
|
+
# strio.eof? # => true
|
|
478
|
+
# strio.gets # => nil
|
|
479
|
+
#
|
|
480
|
+
# strio = StringIO.new('тест') # Four 2-byte characters.
|
|
481
|
+
# strio.pos # => 0
|
|
482
|
+
# strio.gets # => "тест"
|
|
483
|
+
# strio.pos # => 8
|
|
484
|
+
#
|
|
485
|
+
# **Argument `sep`**
|
|
486
|
+
#
|
|
487
|
+
# With only string argument `sep` given, reads a line using that string as the
|
|
488
|
+
# record separator:
|
|
489
|
+
#
|
|
490
|
+
# strio = StringIO.new(TEXT)
|
|
491
|
+
# strio.gets(' ') # => "First "
|
|
492
|
+
# strio.gets(' ') # => "line\nSecond "
|
|
493
|
+
# strio.gets(' ') # => "line\n\nFourth "
|
|
494
|
+
#
|
|
495
|
+
# **Argument `limit`**
|
|
496
|
+
#
|
|
497
|
+
# With only integer argument `limit` given, reads a line using the default
|
|
498
|
+
# record separator; limits the size (in characters) of each line to the given
|
|
499
|
+
# limit:
|
|
500
|
+
#
|
|
501
|
+
# strio = StringIO.new(TEXT)
|
|
502
|
+
# strio.gets(10) # => "First line"
|
|
503
|
+
# strio.gets(10) # => "\n"
|
|
504
|
+
# strio.gets(10) # => "Second lin"
|
|
505
|
+
# strio.gets(10) # => "e\n"
|
|
506
|
+
#
|
|
507
|
+
# **Arguments `sep` and `limit`**
|
|
508
|
+
#
|
|
509
|
+
# With arguments `sep` and `limit` both given, honors both:
|
|
510
|
+
#
|
|
511
|
+
# strio = StringIO.new(TEXT)
|
|
512
|
+
# strio.gets(' ', 10) # => "First "
|
|
513
|
+
# strio.gets(' ', 10) # => "line\nSecon"
|
|
514
|
+
# strio.gets(' ', 10) # => "d "
|
|
515
|
+
#
|
|
516
|
+
# **Position**
|
|
517
|
+
#
|
|
518
|
+
# As stated above, method `gets` reads and returns the next line in the stream.
|
|
519
|
+
#
|
|
520
|
+
# In the examples above each `strio` object starts with its position at
|
|
521
|
+
# beginning-of-stream; but in other cases the position may be anywhere:
|
|
522
|
+
#
|
|
523
|
+
# strio = StringIO.new(TEXT)
|
|
524
|
+
# strio.pos = 12
|
|
525
|
+
# strio.gets # => "econd line\n"
|
|
526
|
+
#
|
|
527
|
+
# The position need not be at a character boundary:
|
|
528
|
+
#
|
|
529
|
+
# strio = StringIO.new('тест') # Four 2-byte characters.
|
|
530
|
+
# strio.pos = 2 # At beginning of second character.
|
|
531
|
+
# strio.gets # => "ест"
|
|
532
|
+
# strio.pos = 3 # In middle of second character.
|
|
533
|
+
# strio.gets # => "\xB5ст"
|
|
534
|
+
#
|
|
535
|
+
# **Special Record Separators**
|
|
536
|
+
#
|
|
537
|
+
# Like some methods in class IO, method `gets` honors two special record
|
|
538
|
+
# separators; see [Special Line
|
|
539
|
+
# Separators](https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Specia
|
|
540
|
+
# l+Line+Separator+Values):
|
|
541
|
+
#
|
|
542
|
+
# strio = StringIO.new(TEXT)
|
|
543
|
+
# strio.gets('') # Read "paragraph" (up to empty line).
|
|
544
|
+
# # => "First line\nSecond line\n\n"
|
|
545
|
+
#
|
|
546
|
+
# strio = StringIO.new(TEXT)
|
|
547
|
+
# strio.gets(nil) # "Slurp": read all.
|
|
548
|
+
# # => "First line\nSecond line\n\nFourth line\nFifth line\n"
|
|
549
|
+
#
|
|
550
|
+
# **Keyword Argument `chomp`**
|
|
551
|
+
#
|
|
552
|
+
# With keyword argument `chomp` given as `true` (the default is `false`),
|
|
553
|
+
# removes the trailing newline (if any) from the returned line:
|
|
554
|
+
#
|
|
555
|
+
# strio = StringIO.new(TEXT)
|
|
556
|
+
# strio.gets # => "First line\n"
|
|
557
|
+
# strio.gets(chomp: true) # => "Second line"
|
|
558
|
+
#
|
|
559
|
+
# Related: StringIO.each_line.
|
|
242
560
|
#
|
|
243
561
|
def gets: (?String sep, ?Integer limit, ?chomp: boolish) -> String?
|
|
244
562
|
|
|
245
563
|
# <!--
|
|
246
564
|
# rdoc-file=ext/stringio/stringio.c
|
|
247
|
-
# -
|
|
565
|
+
# - internal_encoding -> nil
|
|
248
566
|
# -->
|
|
249
|
-
# Returns
|
|
250
|
-
# Otherwise returns `nil`.
|
|
567
|
+
# Returns `nil`; for compatibility with IO.
|
|
251
568
|
#
|
|
252
569
|
def internal_encoding: () -> Encoding
|
|
253
570
|
|
|
254
571
|
# <!--
|
|
255
572
|
# rdoc-file=ext/stringio/stringio.c
|
|
256
|
-
# -
|
|
573
|
+
# - external_encoding -> encoding or nil
|
|
257
574
|
# -->
|
|
258
|
-
# Returns
|
|
259
|
-
#
|
|
575
|
+
# Returns an Encoding object that represents the encoding of the string; see
|
|
576
|
+
# [Encoding](rdoc-ref:Encoding):
|
|
577
|
+
#
|
|
578
|
+
# strio = StringIO.new('foo')
|
|
579
|
+
# strio.external_encoding # => #<Encoding:UTF-8>
|
|
580
|
+
#
|
|
581
|
+
# Returns `nil` if `self` has no string and is in write mode:
|
|
582
|
+
#
|
|
583
|
+
# strio = StringIO.new(nil, 'w+')
|
|
584
|
+
# strio.external_encoding # => nil
|
|
260
585
|
#
|
|
261
586
|
def external_encoding: () -> Encoding
|
|
262
587
|
|
|
@@ -264,7 +589,7 @@ class StringIO
|
|
|
264
589
|
# rdoc-file=ext/stringio/stringio.c
|
|
265
590
|
# - isatty()
|
|
266
591
|
# -->
|
|
267
|
-
# Returns `false
|
|
592
|
+
# Returns `false`; for compatibility with IO.
|
|
268
593
|
#
|
|
269
594
|
def isatty: () -> bool
|
|
270
595
|
|
|
@@ -290,7 +615,7 @@ class StringIO
|
|
|
290
615
|
# rdoc-file=ext/stringio/stringio.c
|
|
291
616
|
# - pid()
|
|
292
617
|
# -->
|
|
293
|
-
# Returns `nil
|
|
618
|
+
# Returns `nil`; for compatibility with IO.
|
|
294
619
|
#
|
|
295
620
|
def pid: () -> nil
|
|
296
621
|
|
|
@@ -391,8 +716,8 @@ class StringIO
|
|
|
391
716
|
# rdoc-file=ext/stringio/stringio.c
|
|
392
717
|
# - seek(offset, whence = SEEK_SET) -> 0
|
|
393
718
|
# -->
|
|
394
|
-
# Sets the
|
|
395
|
-
#
|
|
719
|
+
# Sets the position to the given integer `offset` (in bytes), with respect to a
|
|
720
|
+
# given constant `whence`; see [IO#seek](rdoc-ref:IO#seek).
|
|
396
721
|
#
|
|
397
722
|
def seek: (Integer amount, ?Integer whence) -> Integer
|
|
398
723
|
|
|
@@ -432,7 +757,7 @@ class StringIO
|
|
|
432
757
|
# rdoc-file=ext/stringio/stringio.c
|
|
433
758
|
# - string = other_string -> other_string
|
|
434
759
|
# -->
|
|
435
|
-
#
|
|
760
|
+
# Replaces the stored string with `other_string`, and sets the position to zero;
|
|
436
761
|
# returns `other_string`:
|
|
437
762
|
#
|
|
438
763
|
# StringIO.open('foo') do |strio|
|
|
@@ -446,16 +771,14 @@ class StringIO
|
|
|
446
771
|
# "foo"
|
|
447
772
|
# "bar"
|
|
448
773
|
#
|
|
449
|
-
# Related: StringIO#string (returns the
|
|
774
|
+
# Related: StringIO#string (returns the stored string).
|
|
450
775
|
#
|
|
451
776
|
def string=: (String str) -> String
|
|
452
777
|
|
|
453
778
|
# <!--
|
|
454
779
|
# rdoc-file=ext/stringio/stringio.c
|
|
455
|
-
# -
|
|
456
|
-
# - strio.size -> integer
|
|
780
|
+
# - size -> integer
|
|
457
781
|
# -->
|
|
458
|
-
# Returns the size of the buffer string.
|
|
459
782
|
#
|
|
460
783
|
def size: () -> Integer
|
|
461
784
|
|
|
@@ -497,7 +820,7 @@ class StringIO
|
|
|
497
820
|
def truncate: (Integer) -> 0
|
|
498
821
|
|
|
499
822
|
# <!-- rdoc-file=ext/stringio/stringio.c -->
|
|
500
|
-
# Returns `false
|
|
823
|
+
# Returns `false`; for compatibility with IO.
|
|
501
824
|
#
|
|
502
825
|
def tty?: () -> bool
|
|
503
826
|
|
|
@@ -545,18 +868,27 @@ class StringIO
|
|
|
545
868
|
def codepoints: () { (Integer arg0) -> untyped } -> self
|
|
546
869
|
| () -> ::Enumerator[Integer, self]
|
|
547
870
|
|
|
548
|
-
# <!--
|
|
549
|
-
#
|
|
550
|
-
#
|
|
871
|
+
# <!--
|
|
872
|
+
# rdoc-file=ext/stringio/stringio.c
|
|
873
|
+
# - each_line(*args)
|
|
874
|
+
# -->
|
|
551
875
|
#
|
|
552
876
|
def each_line: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self
|
|
553
877
|
| (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self]
|
|
554
878
|
|
|
555
879
|
# <!-- rdoc-file=ext/stringio/stringio.c -->
|
|
556
|
-
# Returns `
|
|
557
|
-
#
|
|
558
|
-
#
|
|
559
|
-
#
|
|
880
|
+
# Returns whether `self` is positioned at end-of-stream:
|
|
881
|
+
#
|
|
882
|
+
# strio = StringIO.new('foo')
|
|
883
|
+
# strio.pos # => 0
|
|
884
|
+
# strio.eof? # => false
|
|
885
|
+
# strio.read # => "foo"
|
|
886
|
+
# strio.pos # => 3
|
|
887
|
+
# strio.eof? # => true
|
|
888
|
+
# strio.close_read
|
|
889
|
+
# strio.eof? # Raises IOError: not opened for reading
|
|
890
|
+
#
|
|
891
|
+
# Related: StringIO#pos.
|
|
560
892
|
#
|
|
561
893
|
def eof?: () -> bool
|
|
562
894
|
|