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.
Files changed (171) hide show
  1. checksums.yaml +4 -4
  2. data/.clang-format +74 -0
  3. data/.clangd +2 -0
  4. data/.github/workflows/c-check.yml +54 -0
  5. data/.github/workflows/comments.yml +3 -3
  6. data/.github/workflows/ruby.yml +34 -19
  7. data/.github/workflows/typecheck.yml +1 -1
  8. data/.github/workflows/windows.yml +1 -1
  9. data/.gitignore +4 -0
  10. data/README.md +38 -1
  11. data/Rakefile +152 -23
  12. data/config.yml +190 -62
  13. data/core/array.rbs +44 -43
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +3 -2
  16. data/core/enumerable.rbs +89 -2
  17. data/core/errno.rbs +8 -0
  18. data/core/errors.rbs +28 -1
  19. data/core/exception.rbs +2 -2
  20. data/core/fiber.rbs +3 -3
  21. data/core/file.rbs +26 -11
  22. data/core/float.rbs +1 -1
  23. data/core/gc.rbs +422 -281
  24. data/core/hash.rbs +1024 -727
  25. data/core/io/wait.rbs +11 -33
  26. data/core/io.rbs +6 -4
  27. data/core/kernel.rbs +49 -43
  28. data/core/marshal.rbs +1 -1
  29. data/core/match_data.rbs +1 -1
  30. data/core/math.rbs +42 -3
  31. data/core/method.rbs +14 -6
  32. data/core/module.rbs +71 -11
  33. data/core/nil_class.rbs +3 -3
  34. data/core/numeric.rbs +8 -8
  35. data/core/object.rbs +3 -3
  36. data/core/object_space.rbs +13 -0
  37. data/{stdlib/pathname/0 → core}/pathname.rbs +253 -352
  38. data/core/proc.rbs +15 -8
  39. data/core/process.rbs +2 -2
  40. data/core/ractor.rbs +278 -437
  41. data/core/range.rbs +6 -7
  42. data/core/rbs/unnamed/argf.rbs +1 -1
  43. data/core/rbs/unnamed/env_class.rbs +1 -1
  44. data/core/rbs/unnamed/random.rbs +4 -2
  45. data/core/regexp.rbs +22 -17
  46. data/core/ruby_vm.rbs +6 -4
  47. data/core/rubygems/errors.rbs +3 -70
  48. data/core/rubygems/rubygems.rbs +11 -79
  49. data/core/set.rbs +439 -332
  50. data/core/string.rbs +2897 -1117
  51. data/core/struct.rbs +1 -1
  52. data/core/symbol.rbs +4 -4
  53. data/core/thread.rbs +83 -20
  54. data/core/time.rbs +35 -9
  55. data/core/unbound_method.rbs +14 -6
  56. data/docs/aliases.md +79 -0
  57. data/docs/collection.md +2 -2
  58. data/docs/gem.md +0 -1
  59. data/docs/sigs.md +3 -3
  60. data/ext/rbs_extension/ast_translation.c +1016 -0
  61. data/ext/rbs_extension/ast_translation.h +37 -0
  62. data/ext/rbs_extension/class_constants.c +157 -0
  63. data/{include/rbs/constants.h → ext/rbs_extension/class_constants.h} +7 -1
  64. data/ext/rbs_extension/compat.h +10 -0
  65. data/ext/rbs_extension/extconf.rb +25 -1
  66. data/ext/rbs_extension/legacy_location.c +317 -0
  67. data/ext/rbs_extension/legacy_location.h +45 -0
  68. data/ext/rbs_extension/main.c +365 -14
  69. data/ext/rbs_extension/rbs_extension.h +6 -21
  70. data/ext/rbs_extension/rbs_string_bridging.c +9 -0
  71. data/ext/rbs_extension/rbs_string_bridging.h +24 -0
  72. data/include/rbs/ast.h +687 -0
  73. data/include/rbs/defines.h +86 -0
  74. data/include/rbs/lexer.h +199 -0
  75. data/include/rbs/location.h +59 -0
  76. data/include/rbs/parser.h +135 -0
  77. data/include/rbs/string.h +49 -0
  78. data/include/rbs/util/rbs_allocator.h +59 -0
  79. data/include/rbs/util/rbs_assert.h +20 -0
  80. data/include/rbs/util/rbs_buffer.h +83 -0
  81. data/include/rbs/util/rbs_constant_pool.h +6 -67
  82. data/include/rbs/util/rbs_encoding.h +282 -0
  83. data/include/rbs/util/rbs_unescape.h +23 -0
  84. data/include/rbs.h +1 -2
  85. data/lib/rbs/annotate/formatter.rb +3 -13
  86. data/lib/rbs/annotate/rdoc_annotator.rb +3 -1
  87. data/lib/rbs/annotate/rdoc_source.rb +1 -1
  88. data/lib/rbs/cli/validate.rb +2 -2
  89. data/lib/rbs/cli.rb +1 -1
  90. data/lib/rbs/collection/config/lockfile_generator.rb +1 -0
  91. data/lib/rbs/definition_builder/ancestor_builder.rb +5 -5
  92. data/lib/rbs/environment.rb +64 -59
  93. data/lib/rbs/environment_loader.rb +1 -1
  94. data/lib/rbs/errors.rb +1 -1
  95. data/lib/rbs/parser_aux.rb +5 -0
  96. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  97. data/lib/rbs/resolver/type_name_resolver.rb +124 -38
  98. data/lib/rbs/test/type_check.rb +13 -0
  99. data/lib/rbs/types.rb +3 -1
  100. data/lib/rbs/version.rb +1 -1
  101. data/lib/rbs.rb +1 -1
  102. data/lib/rdoc/discover.rb +1 -1
  103. data/lib/rdoc_plugin/parser.rb +3 -3
  104. data/sig/annotate/formatter.rbs +2 -2
  105. data/sig/annotate/rdoc_annotater.rbs +1 -1
  106. data/sig/environment.rbs +57 -6
  107. data/sig/manifest.yaml +0 -1
  108. data/sig/parser.rbs +20 -0
  109. data/sig/resolver/type_name_resolver.rbs +38 -7
  110. data/sig/types.rbs +4 -1
  111. data/src/ast.c +1256 -0
  112. data/src/lexer.c +2956 -0
  113. data/src/lexer.re +147 -0
  114. data/src/lexstate.c +205 -0
  115. data/src/location.c +71 -0
  116. data/src/parser.c +3495 -0
  117. data/src/string.c +90 -0
  118. data/src/util/rbs_allocator.c +152 -0
  119. data/src/util/rbs_assert.c +21 -0
  120. data/src/util/rbs_buffer.c +54 -0
  121. data/src/util/rbs_constant_pool.c +16 -86
  122. data/src/util/rbs_encoding.c +21308 -0
  123. data/src/util/rbs_unescape.c +131 -0
  124. data/stdlib/cgi/0/core.rbs +2 -396
  125. data/stdlib/cgi/0/manifest.yaml +1 -0
  126. data/stdlib/cgi-escape/0/escape.rbs +153 -0
  127. data/stdlib/coverage/0/coverage.rbs +3 -1
  128. data/stdlib/delegate/0/delegator.rbs +10 -7
  129. data/stdlib/erb/0/erb.rbs +737 -347
  130. data/stdlib/fileutils/0/fileutils.rbs +18 -13
  131. data/stdlib/forwardable/0/forwardable.rbs +3 -0
  132. data/stdlib/json/0/json.rbs +67 -48
  133. data/stdlib/net-http/0/net-http.rbs +3 -0
  134. data/stdlib/objspace/0/objspace.rbs +8 -3
  135. data/stdlib/open-uri/0/open-uri.rbs +40 -0
  136. data/stdlib/openssl/0/openssl.rbs +182 -149
  137. data/stdlib/optparse/0/optparse.rbs +3 -3
  138. data/stdlib/rdoc/0/code_object.rbs +2 -2
  139. data/stdlib/rdoc/0/comment.rbs +2 -0
  140. data/stdlib/rdoc/0/options.rbs +76 -0
  141. data/stdlib/rdoc/0/rdoc.rbs +7 -5
  142. data/stdlib/rdoc/0/store.rbs +1 -1
  143. data/stdlib/resolv/0/resolv.rbs +25 -68
  144. data/stdlib/ripper/0/ripper.rbs +5 -2
  145. data/stdlib/singleton/0/singleton.rbs +3 -0
  146. data/stdlib/socket/0/socket.rbs +13 -1
  147. data/stdlib/socket/0/tcp_socket.rbs +10 -2
  148. data/stdlib/stringio/0/stringio.rbs +412 -80
  149. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  150. data/stdlib/tempfile/0/tempfile.rbs +1 -1
  151. data/stdlib/tsort/0/cyclic.rbs +3 -0
  152. data/stdlib/uri/0/common.rbs +11 -2
  153. data/stdlib/uri/0/file.rbs +1 -1
  154. data/stdlib/uri/0/generic.rbs +16 -15
  155. data/stdlib/uri/0/rfc2396_parser.rbs +6 -7
  156. data/stdlib/zlib/0/zstream.rbs +1 -0
  157. metadata +41 -18
  158. data/ext/rbs_extension/lexer.c +0 -2728
  159. data/ext/rbs_extension/lexer.h +0 -179
  160. data/ext/rbs_extension/lexer.re +0 -147
  161. data/ext/rbs_extension/lexstate.c +0 -175
  162. data/ext/rbs_extension/location.c +0 -325
  163. data/ext/rbs_extension/location.h +0 -85
  164. data/ext/rbs_extension/parser.c +0 -2982
  165. data/ext/rbs_extension/parser.h +0 -18
  166. data/ext/rbs_extension/parserstate.c +0 -411
  167. data/ext/rbs_extension/parserstate.h +0 -163
  168. data/ext/rbs_extension/unescape.c +0 -32
  169. data/include/rbs/ruby_objs.h +0 -72
  170. data/src/constants.c +0 -153
  171. 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 [IO](rdoc-ref:IO); see
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
- # Note that `mode` defaults to `'r'` if `string` is frozen.
26
+ # Returns a new StringIO instance formed from `string` and `mode`; the instance
27
+ # should be closed when no longer needed:
17
28
  #
18
- # Returns a new StringIO instance formed from `string` and `mode`; see [Access
19
- # Modes](rdoc-ref:File@Access+Modes):
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 # => #<StringIO>
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
- # The instance should be closed when no longer needed.
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 (accepts block; closes automatically).
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+') {|strio| ... }
56
+ # - StringIO.open(string = '', mode = 'r+') -> new_stringio
57
+ # - StringIO.open(string = '', mode = 'r+') {|strio| ... } -> object
33
58
  # -->
34
- # Note that `mode` defaults to `'r'` if `string` is frozen.
59
+ # Creates new StringIO instance by calling `StringIO.new(string, mode)`.
35
60
  #
36
- # Creates a new StringIO instance formed from `string` and `mode`; see [Access
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 block's
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| p 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
- # Raises IOError if reading or writing is attempted.
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
- # Raises IOError if reading is attempted.
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
- # Raises IOError if writing is attempted.
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 `true` if `self` is closed for both reading and writing, `false`
105
- # otherwise.
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 `true` if `self` is closed for reading, `false` otherwise.
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 `true` if `self` is closed for writing, `false` otherwise.
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
- # see [Byte IO](rdoc-ref:IO@Byte+IO).
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
- # With no block given, returns an enumerator.
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 {|c| ... } -> self
240
+ # - each_char {|char| ... } -> self
152
241
  # -->
153
242
  # With a block given, calls the block with each remaining character in the
154
- # stream; see [Character IO](rdoc-ref:IO@Character+IO).
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
- # With no block given, returns an enumerator.
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 remaining codepoint in the
166
- # stream; see [Codepoint IO](rdoc-ref:IO@Codepoint+IO).
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 an enumerator.
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 `true` if positioned at end-of-stream, `false` otherwise; see
178
- # [Position](rdoc-ref:IO@Position).
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
- # Raises IOError if the stream is not opened for reading.
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`. Just for compatibility to IO.
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 an object itself. Just for compatibility to IO.
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. Just for compatibility to IO.
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 -> byte or nil
379
+ # - getbyte -> integer or nil
219
380
  # -->
220
- # Reads and returns the next 8-bit byte from the stream; see [Byte
221
- # IO](rdoc-ref:IO@Byte+IO).
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; see [Character
230
- # IO](rdoc-ref:IO@Character+IO).
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; assigns the return value to `$_`;
241
- # see [Line IO](rdoc-ref:IO@Line+IO).
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
- # - strio.internal_encoding => encoding
565
+ # - internal_encoding -> nil
248
566
  # -->
249
- # Returns the Encoding of the internal string if conversion is specified.
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
- # - strio.external_encoding => encoding
573
+ # - external_encoding -> encoding or nil
257
574
  # -->
258
- # Returns the Encoding object that represents the encoding of the file. If the
259
- # stream is write mode and no encoding is specified, returns `nil`.
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`. Just for compatibility to IO.
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`. Just for compatibility to IO.
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 current position to the given integer `offset` (in bytes), with
395
- # respect to a given constant `whence`; see [Position](rdoc-ref:IO@Position).
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
- # Assigns the underlying string as `other_string`, and sets position to zero;
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 underlying string).
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
- # - strio.length -> integer
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`. Just for compatibility to IO.
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
- # <!-- rdoc-file=ext/stringio/stringio.c -->
549
- # Calls the block with each remaining line read from the stream; does nothing if
550
- # already at end-of-file; returns `self`. See [Line IO](rdoc-ref:IO@Line+IO).
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 `true` if positioned at end-of-stream, `false` otherwise; see
557
- # [Position](rdoc-ref:IO@Position).
558
- #
559
- # Raises IOError if the stream is not opened for reading.
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