rbs 3.10.0 → 4.0.0.dev.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 (202) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +24 -35
  4. data/.github/workflows/typecheck.yml +3 -1
  5. data/.github/workflows/windows.yml +2 -2
  6. data/.gitignore +0 -4
  7. data/CHANGELOG.md +0 -88
  8. data/README.md +1 -38
  9. data/Rakefile +20 -142
  10. data/Steepfile +1 -0
  11. data/config.yml +43 -1
  12. data/core/array.rbs +46 -100
  13. data/core/complex.rbs +21 -32
  14. data/core/dir.rbs +2 -2
  15. data/core/encoding.rbs +9 -6
  16. data/core/enumerable.rbs +3 -90
  17. data/core/enumerator.rbs +1 -18
  18. data/core/errno.rbs +0 -8
  19. data/core/errors.rbs +1 -28
  20. data/core/exception.rbs +2 -2
  21. data/core/fiber.rbs +4 -5
  22. data/core/file.rbs +12 -27
  23. data/core/file_test.rbs +1 -1
  24. data/core/float.rbs +22 -209
  25. data/core/gc.rbs +281 -417
  26. data/core/hash.rbs +727 -1024
  27. data/core/integer.rbs +38 -78
  28. data/core/io/buffer.rbs +7 -18
  29. data/core/io/wait.rbs +33 -11
  30. data/core/io.rbs +12 -14
  31. data/core/kernel.rbs +51 -57
  32. data/core/marshal.rbs +1 -1
  33. data/core/match_data.rbs +1 -1
  34. data/core/math.rbs +3 -42
  35. data/core/method.rbs +6 -14
  36. data/core/module.rbs +17 -88
  37. data/core/nil_class.rbs +3 -3
  38. data/core/numeric.rbs +16 -16
  39. data/core/object.rbs +3 -3
  40. data/core/object_space.rbs +15 -21
  41. data/core/proc.rbs +8 -15
  42. data/core/process.rbs +2 -2
  43. data/core/ractor.rbs +437 -278
  44. data/core/range.rbs +8 -7
  45. data/core/rational.rbs +24 -37
  46. data/core/rbs/unnamed/argf.rbs +2 -2
  47. data/core/rbs/unnamed/env_class.rbs +1 -1
  48. data/core/rbs/unnamed/random.rbs +2 -4
  49. data/core/regexp.rbs +20 -25
  50. data/core/ruby_vm.rbs +4 -6
  51. data/core/rubygems/errors.rbs +70 -3
  52. data/core/rubygems/rubygems.rbs +79 -11
  53. data/core/rubygems/version.rbs +3 -2
  54. data/core/set.rbs +359 -488
  55. data/core/string.rbs +1228 -3153
  56. data/core/struct.rbs +1 -1
  57. data/core/symbol.rbs +4 -4
  58. data/core/thread.rbs +29 -92
  59. data/core/time.rbs +9 -35
  60. data/core/trace_point.rbs +4 -7
  61. data/core/unbound_method.rbs +6 -14
  62. data/docs/collection.md +2 -2
  63. data/docs/gem.md +1 -0
  64. data/docs/sigs.md +3 -3
  65. data/ext/rbs_extension/ast_translation.c +1077 -944
  66. data/ext/rbs_extension/ast_translation.h +0 -7
  67. data/ext/rbs_extension/class_constants.c +83 -71
  68. data/ext/rbs_extension/class_constants.h +7 -4
  69. data/ext/rbs_extension/extconf.rb +2 -24
  70. data/ext/rbs_extension/legacy_location.c +172 -173
  71. data/ext/rbs_extension/legacy_location.h +3 -8
  72. data/ext/rbs_extension/main.c +289 -239
  73. data/ext/rbs_extension/rbs_extension.h +0 -3
  74. data/ext/rbs_extension/rbs_string_bridging.h +0 -4
  75. data/include/rbs/ast.h +98 -37
  76. data/include/rbs/defines.h +12 -38
  77. data/include/rbs/lexer.h +114 -126
  78. data/include/rbs/location.h +14 -14
  79. data/include/rbs/parser.h +37 -21
  80. data/include/rbs/string.h +5 -3
  81. data/include/rbs/util/rbs_allocator.h +19 -40
  82. data/include/rbs/util/rbs_assert.h +1 -12
  83. data/include/rbs/util/rbs_constant_pool.h +3 -3
  84. data/include/rbs/util/rbs_encoding.h +1 -3
  85. data/include/rbs/util/rbs_unescape.h +1 -2
  86. data/lib/rbs/ast/ruby/annotations.rb +119 -0
  87. data/lib/rbs/ast/ruby/comment_block.rb +221 -0
  88. data/lib/rbs/ast/ruby/declarations.rb +86 -0
  89. data/lib/rbs/ast/ruby/helpers/constant_helper.rb +24 -0
  90. data/lib/rbs/ast/ruby/helpers/location_helper.rb +15 -0
  91. data/lib/rbs/ast/ruby/members.rb +213 -0
  92. data/lib/rbs/buffer.rb +104 -24
  93. data/lib/rbs/cli/validate.rb +40 -35
  94. data/lib/rbs/cli.rb +5 -6
  95. data/lib/rbs/collection/config/lockfile_generator.rb +0 -1
  96. data/lib/rbs/collection.rb +0 -1
  97. data/lib/rbs/definition.rb +6 -1
  98. data/lib/rbs/definition_builder/ancestor_builder.rb +65 -62
  99. data/lib/rbs/definition_builder/method_builder.rb +45 -30
  100. data/lib/rbs/definition_builder.rb +44 -9
  101. data/lib/rbs/environment/class_entry.rb +69 -0
  102. data/lib/rbs/environment/module_entry.rb +66 -0
  103. data/lib/rbs/environment.rb +244 -218
  104. data/lib/rbs/environment_loader.rb +3 -3
  105. data/lib/rbs/errors.rb +5 -4
  106. data/lib/rbs/inline_parser/comment_association.rb +117 -0
  107. data/lib/rbs/inline_parser.rb +206 -0
  108. data/lib/rbs/location_aux.rb +35 -3
  109. data/lib/rbs/parser_aux.rb +11 -6
  110. data/lib/rbs/prototype/runtime.rb +2 -2
  111. data/lib/rbs/resolver/constant_resolver.rb +2 -2
  112. data/lib/rbs/resolver/type_name_resolver.rb +38 -124
  113. data/lib/rbs/source.rb +99 -0
  114. data/lib/rbs/subtractor.rb +4 -3
  115. data/lib/rbs/test/type_check.rb +0 -14
  116. data/lib/rbs/types.rb +1 -3
  117. data/lib/rbs/version.rb +1 -1
  118. data/lib/rbs.rb +13 -1
  119. data/lib/rdoc/discover.rb +1 -1
  120. data/lib/rdoc_plugin/parser.rb +1 -1
  121. data/rbs.gemspec +1 -0
  122. data/sig/ancestor_builder.rbs +1 -1
  123. data/sig/ast/ruby/annotations.rbs +110 -0
  124. data/sig/ast/ruby/comment_block.rbs +119 -0
  125. data/sig/ast/ruby/declarations.rbs +60 -0
  126. data/sig/ast/ruby/helpers/constant_helper.rbs +11 -0
  127. data/sig/ast/ruby/helpers/location_helper.rbs +15 -0
  128. data/sig/ast/ruby/members.rbs +72 -0
  129. data/sig/buffer.rbs +63 -5
  130. data/sig/definition.rbs +1 -0
  131. data/sig/definition_builder.rbs +1 -1
  132. data/sig/environment/class_entry.rbs +50 -0
  133. data/sig/environment/module_entry.rbs +50 -0
  134. data/sig/environment.rbs +28 -133
  135. data/sig/errors.rbs +13 -6
  136. data/sig/inline_parser/comment_association.rbs +71 -0
  137. data/sig/inline_parser.rbs +87 -0
  138. data/sig/location.rbs +32 -7
  139. data/sig/manifest.yaml +1 -0
  140. data/sig/method_builder.rbs +7 -4
  141. data/sig/parser.rbs +16 -20
  142. data/sig/resolver/type_name_resolver.rbs +7 -38
  143. data/sig/source.rbs +48 -0
  144. data/sig/types.rbs +1 -4
  145. data/src/ast.c +290 -201
  146. data/src/lexer.c +2813 -2902
  147. data/src/lexer.re +4 -0
  148. data/src/lexstate.c +155 -169
  149. data/src/location.c +40 -40
  150. data/src/parser.c +2665 -2433
  151. data/src/string.c +48 -0
  152. data/src/util/rbs_allocator.c +77 -80
  153. data/src/util/rbs_assert.c +10 -10
  154. data/src/util/rbs_buffer.c +2 -2
  155. data/src/util/rbs_constant_pool.c +15 -13
  156. data/src/util/rbs_encoding.c +4062 -20097
  157. data/src/util/rbs_unescape.c +48 -85
  158. data/stdlib/bigdecimal/0/big_decimal.rbs +82 -100
  159. data/stdlib/bigdecimal-math/0/big_math.rbs +8 -169
  160. data/stdlib/cgi/0/core.rbs +396 -2
  161. data/stdlib/cgi/0/manifest.yaml +0 -1
  162. data/stdlib/coverage/0/coverage.rbs +1 -3
  163. data/stdlib/date/0/date.rbs +59 -67
  164. data/stdlib/date/0/date_time.rbs +1 -1
  165. data/stdlib/delegate/0/delegator.rbs +7 -10
  166. data/stdlib/erb/0/erb.rbs +347 -737
  167. data/stdlib/fileutils/0/fileutils.rbs +13 -18
  168. data/stdlib/forwardable/0/forwardable.rbs +0 -3
  169. data/stdlib/json/0/json.rbs +48 -68
  170. data/stdlib/net-http/0/net-http.rbs +0 -3
  171. data/stdlib/objspace/0/objspace.rbs +4 -9
  172. data/stdlib/open-uri/0/open-uri.rbs +0 -40
  173. data/stdlib/openssl/0/openssl.rbs +228 -331
  174. data/stdlib/optparse/0/optparse.rbs +3 -3
  175. data/{core → stdlib/pathname/0}/pathname.rbs +355 -255
  176. data/stdlib/psych/0/psych.rbs +3 -3
  177. data/stdlib/rdoc/0/rdoc.rbs +1 -1
  178. data/stdlib/resolv/0/resolv.rbs +68 -25
  179. data/stdlib/ripper/0/ripper.rbs +2 -5
  180. data/stdlib/singleton/0/singleton.rbs +0 -3
  181. data/stdlib/socket/0/socket.rbs +1 -13
  182. data/stdlib/socket/0/tcp_socket.rbs +2 -10
  183. data/stdlib/stringio/0/stringio.rbs +85 -1176
  184. data/stdlib/strscan/0/string_scanner.rbs +31 -31
  185. data/stdlib/tempfile/0/tempfile.rbs +3 -3
  186. data/stdlib/time/0/time.rbs +1 -1
  187. data/stdlib/timeout/0/timeout.rbs +7 -63
  188. data/stdlib/tsort/0/cyclic.rbs +0 -3
  189. data/stdlib/uri/0/common.rbs +2 -11
  190. data/stdlib/uri/0/file.rbs +1 -1
  191. data/stdlib/uri/0/generic.rbs +16 -17
  192. data/stdlib/uri/0/rfc2396_parser.rbs +7 -6
  193. data/stdlib/zlib/0/zstream.rbs +0 -1
  194. metadata +40 -12
  195. data/.clang-format +0 -74
  196. data/.clangd +0 -2
  197. data/.github/workflows/c-check.yml +0 -54
  198. data/core/ruby.rbs +0 -53
  199. data/docs/aliases.md +0 -79
  200. data/docs/encoding.md +0 -56
  201. data/ext/rbs_extension/compat.h +0 -10
  202. data/stdlib/cgi-escape/0/escape.rbs +0 -153
@@ -1,561 +1,50 @@
1
1
  # <!-- rdoc-file=ext/stringio/stringio.c -->
2
- # Class StringIO supports accessing a string as a stream,
3
- # similar in some ways to [class
4
- # IO](https://docs.ruby-lang.org/en/master/IO.html).
5
- # You can create a StringIO instance using:
6
- # * StringIO.new: returns a new StringIO object containing the given string.
7
- # * StringIO.open: passes a new StringIO object to the given block.
8
- # Like an IO stream, a StringIO stream has certain properties:
9
- # * **Read/write mode**: whether the stream may be read, written, appended to,
10
- # etc.;
11
- # see [Read/Write Mode](rdoc-ref:StringIO@Read-2FWrite+Mode).
12
- # * **Data mode**: text-only or binary;
13
- # see [Data Mode](rdoc-ref:StringIO@Data+Mode).
14
- # * **Encodings**: internal and external encodings;
15
- # see [Encodings](rdoc-ref:StringIO@Encodings).
16
- # * **Position**: where in the stream the next read or write is to occur;
17
- # see [Position](rdoc-ref:StringIO@Position).
18
- # * **Line number**: a special, line-oriented, "position" (different from the
19
- # position mentioned above);
20
- # see [Line Number](rdoc-ref:StringIO@Line+Number).
21
- # * **Open/closed**: whether the stream is open or closed, for reading or
22
- # writing.
23
- # see [Open/Closed Streams](rdoc-ref:StringIO@Open-2FClosed+Streams).
24
- # * **BOM**: byte mark order;
25
- # see [Byte Order Mark](rdoc-ref:StringIO@BOM+-28Byte+Order+Mark-29).
26
- # ## About the Examples
27
- # Examples on this page assume that StringIO has been required:
28
- # require 'stringio'
29
- #
30
- # And that this constant has been defined:
31
- # TEXT = <<EOT
32
- # First line
33
- # Second line
34
- #
35
- # Fourth line
36
- # Fifth line
37
- # EOT
38
- #
39
- # ## Stream Properties
40
- # ### Read/Write Mode
41
- # #### Summary
42
- # Mode |Initial Clear?| Read | Write
43
- # -------------------|--------------|--------|--------
44
- # `'r'`: read-only | No |Anywhere| Error
45
- # `'w'`: write-only | Yes | Error |Anywhere
46
- # `'a'`: append-only | No | Error |End only
47
- # `'r+'`: read/write | No |Anywhere|Anywhere
48
- # `'w+'`: read-write | Yes |Anywhere|Anywhere
49
- # `'a+'`: read/append| No |Anywhere|End only
50
- # Each section below describes a read/write mode.
51
- # Any of the modes may be given as a string or as file constants;
52
- # example:
53
- # strio = StringIO.new('foo', 'a')
54
- # strio = StringIO.new('foo', File::WRONLY | File::APPEND)
55
- #
56
- # #### `'r'`: Read-Only
57
- # Mode specified as one of:
58
- # * String: `'r'`.
59
- # * Constant: `File::RDONLY`.
60
- # Initial state:
61
- # strio = StringIO.new('foobarbaz', 'r')
62
- # strio.pos # => 0 # Beginning-of-stream.
63
- # strio.string # => "foobarbaz" # Not cleared.
64
- #
65
- # May be read anywhere:
66
- # strio.gets(3) # => "foo"
67
- # strio.gets(3) # => "bar"
68
- # strio.pos = 9
69
- # strio.gets(3) # => nil
70
- #
71
- # May not be written:
72
- # strio.write('foo') # Raises IOError: not opened for writing
73
- #
74
- # #### `'w'`: Write-Only
75
- # Mode specified as one of:
76
- # * String: `'w'`.
77
- # * Constant: `File::WRONLY`.
78
- # Initial state:
79
- # strio = StringIO.new('foo', 'w')
80
- # strio.pos # => 0 # Beginning of stream.
81
- # strio.string # => "" # Initially cleared.
82
- #
83
- # May be written anywhere (even past end-of-stream):
84
- # strio.write('foobar')
85
- # strio.string # => "foobar"
86
- # strio.rewind
87
- # strio.write('FOO')
88
- # strio.string # => "FOObar"
89
- # strio.pos = 3
90
- # strio.write('BAR')
91
- # strio.string # => "FOOBAR"
92
- # strio.pos = 9
93
- # strio.write('baz')
94
- # strio.string # => "FOOBAR\u0000\u0000\u0000baz" # Null-padded.
95
- #
96
- # May not be read:
97
- # strio.read # Raises IOError: not opened for reading
98
- #
99
- # #### `'a'`: Append-Only
100
- # Mode specified as one of:
101
- # * String: `'a'`.
102
- # * Constant: `File::WRONLY | File::APPEND`.
103
- # Initial state:
104
- # strio = StringIO.new('foo', 'a')
105
- # strio.pos # => 0 # Beginning-of-stream.
106
- # strio.string # => "foo" # Not cleared.
107
- #
108
- # May be written only at the end; position does not affect writing:
109
- # strio.write('bar')
110
- # strio.string # => "foobar"
111
- # strio.write('baz')
112
- # strio.string # => "foobarbaz"
113
- # strio.pos = 400
114
- # strio.write('bat')
115
- # strio.string # => "foobarbazbat"
116
- #
117
- # May not be read:
118
- # strio.gets # Raises IOError: not opened for reading
119
- #
120
- # #### `'r+'`: Read/Write
121
- # Mode specified as one of:
122
- # * String: `'r+'`.
123
- # * Constant: `File::RDRW`.
124
- # Initial state:
125
- # strio = StringIO.new('foobar', 'r+')
126
- # strio.pos # => 0 # Beginning-of-stream.
127
- # strio.string # => "foobar" # Not cleared.
128
- #
129
- # May be written anywhere (even past end-of-stream):
130
- # strio.write('FOO')
131
- # strio.string # => "FOObar"
132
- # strio.write('BAR')
133
- # strio.string # => "FOOBAR"
134
- # strio.write('BAZ')
135
- # strio.string # => "FOOBARBAZ"
136
- # strio.pos = 12
137
- # strio.write('BAT')
138
- # strio.string # => "FOOBARBAZ\u0000\u0000\u0000BAT" # Null padded.
139
- #
140
- # May be read anywhere:
141
- # strio.pos = 0
142
- # strio.gets(3) # => "FOO"
143
- # strio.pos = 6
144
- # strio.gets(3) # => "BAZ"
145
- # strio.pos = 400
146
- # strio.gets(3) # => nil
147
- #
148
- # #### `'w+'`: Read/Write (Initially Clear)
149
- # Mode specified as one of:
150
- # * String: `'w+'`.
151
- # * Constant: `File::RDWR | File::TRUNC`.
152
- # Initial state:
153
- # strio = StringIO.new('foo', 'w+')
154
- # strio.pos # => 0 # Beginning-of-stream.
155
- # strio.string # => "" # Truncated.
156
- #
157
- # May be written anywhere (even past end-of-stream):
158
- # strio.write('foobar')
159
- # strio.string # => "foobar"
160
- # strio.rewind
161
- # strio.write('FOO')
162
- # strio.string # => "FOObar"
163
- # strio.write('BAR')
164
- # strio.string # => "FOOBAR"
165
- # strio.write('BAZ')
166
- # strio.string # => "FOOBARBAZ"
167
- # strio.pos = 12
168
- # strio.write('BAT')
169
- # strio.string # => "FOOBARBAZ\u0000\u0000\u0000BAT" # Null-padded.
170
- #
171
- # May be read anywhere:
172
- # strio.rewind
173
- # strio.gets(3) # => "FOO"
174
- # strio.gets(3) # => "BAR"
175
- # strio.pos = 12
176
- # strio.gets(3) # => "BAT"
177
- # strio.pos = 400
178
- # strio.gets(3) # => nil
2
+ # IO streams for strings, with access similar to [IO](rdoc-ref:IO); see
3
+ # [IO](rdoc-ref:IO).
179
4
  #
180
- # #### `'a+'`: Read/Append
181
- # Mode specified as one of:
182
- # * String: `'a+'`.
183
- # * Constant: `File::RDWR | File::APPEND`.
184
- # Initial state:
185
- # strio = StringIO.new('foo', 'a+')
186
- # strio.pos # => 0 # Beginning-of-stream.
187
- # strio.string # => "foo" # Not cleared.
5
+ # ### About the Examples
188
6
  #
189
- # May be written only at the end; #rewind; position does not affect writing:
190
- # strio.write('bar')
191
- # strio.string # => "foobar"
192
- # strio.write('baz')
193
- # strio.string # => "foobarbaz"
194
- # strio.pos = 400
195
- # strio.write('bat')
196
- # strio.string # => "foobarbazbat"
197
- #
198
- # May be read anywhere:
199
- # strio.rewind
200
- # strio.gets(3) # => "foo"
201
- # strio.gets(3) # => "bar"
202
- # strio.pos = 9
203
- # strio.gets(3) # => "bat"
204
- # strio.pos = 400
205
- # strio.gets(3) # => nil
206
- #
207
- # ### Data Mode
208
- # To specify whether the stream is to be treated as text or as binary data,
209
- # either of the following may be suffixed to any of the string read/write modes
210
- # above:
211
- # * `'t'`: Text;
212
- # initializes the encoding as Encoding::UTF_8.
213
- # * `'b'`: Binary;
214
- # initializes the encoding as Encoding::ASCII_8BIT.
215
- # If neither is given, the stream defaults to text data.
216
- # Examples:
217
- # strio = StringIO.new('foo', 'rt')
218
- # strio.external_encoding # => #<Encoding:UTF-8>
219
- # data = "\u9990\u9991\u9992\u9993\u9994"
220
- # strio = StringIO.new(data, 'rb')
221
- # strio.external_encoding # => #<Encoding:BINARY (ASCII-8BIT)>
222
- #
223
- # When the data mode is specified, the read/write mode may not be omitted:
224
- # StringIO.new(data, 'b') # Raises ArgumentError: invalid access mode b
225
- #
226
- # A text stream may be changed to binary by calling instance method #binmode;
227
- # a binary stream may not be changed to text.
228
- # ### Encodings
229
- # A stream has an encoding; see
230
- # [Encodings](https://docs.ruby-lang.org/en/master/language/encodings_rdoc.html)
231
- # .
232
- # The initial encoding for a new or re-opened stream depends on its [data
233
- # mode](rdoc-ref:StringIO@Data+Mode):
234
- # * Text: `Encoding::UTF_8`.
235
- # * Binary: `Encoding::ASCII_8BIT`.
236
- # These instance methods are relevant:
237
- # * #external_encoding: returns the current encoding of the stream as an
238
- # `Encoding` object.
239
- # * #internal_encoding: returns `nil`; a stream does not have an internal
240
- # encoding.
241
- # * #set_encoding: sets the encoding for the stream.
242
- # * #set_encoding_by_bom: sets the encoding for the stream to the stream's BOM
243
- # (byte order mark).
244
- # Examples:
245
- # strio = StringIO.new('foo', 'rt') # Text mode.
246
- # strio.external_encoding # => #<Encoding:UTF-8>
247
- # data = "\u9990\u9991\u9992\u9993\u9994"
248
- # strio = StringIO.new(data, 'rb') # Binary mode.
249
- # strio.external_encoding # => #<Encoding:BINARY (ASCII-8BIT)>
250
- # strio = StringIO.new('foo')
251
- # strio.external_encoding # => #<Encoding:UTF-8>
252
- # strio.set_encoding('US-ASCII')
253
- # strio.external_encoding # => #<Encoding:US-ASCII>
254
- #
255
- # ### Position
256
- # A stream has a *position*, and integer offset (in bytes) into the stream.
257
- # The initial position of a stream is zero.
258
- # #### Getting and Setting the Position
259
- # Each of these methods initializes (to zero) the position of a new or re-opened
260
- # stream:
261
- # * ::new: returns a new stream.
262
- # * ::open: passes a new stream to the block.
263
- # * #reopen: re-initializes the stream.
264
- # Each of these methods queries, gets, or sets the position, without otherwise
265
- # changing the stream:
266
- # * #eof?: returns whether the position is at end-of-stream.
267
- # * #pos: returns the position.
268
- # * #pos=: sets the position.
269
- # * #rewind: sets the position to zero.
270
- # * #seek: sets the position.
271
- # Examples:
272
- # strio = StringIO.new('foobar')
273
- # strio.pos # => 0
274
- # strio.pos = 3
275
- # strio.pos # => 3
276
- # strio.eof? # => false
277
- # strio.rewind
278
- # strio.pos # => 0
279
- # strio.seek(0, IO::SEEK_END)
280
- # strio.pos # => 6
281
- # strio.eof? # => true
282
- #
283
- # #### Position Before and After Reading
284
- # Except for #pread, a stream reading method (see [Basic
285
- # Reading](rdoc-ref:StringIO@Basic+Reading))
286
- # begins reading at the current position.
287
- # Except for #pread, a read method advances the position past the read
288
- # substring.
289
- # Examples:
290
- # strio = StringIO.new(TEXT)
291
- # strio.string # => "First line\nSecond line\n\nFourth line\nFifth line\n"
292
- # strio.pos # => 0
293
- # strio.getc # => "F"
294
- # strio.pos # => 1
295
- # strio.gets # => "irst line\n"
296
- # strio.pos # => 11
297
- # strio.pos = 24
298
- # strio.gets # => "Fourth line\n"
299
- # strio.pos # => 36
300
- #
301
- # strio = StringIO.new('тест') # Four 2-byte characters.
302
- # strio.pos = 0 # At first byte of first character.
303
- # strio.read # => "тест"
304
- # strio.pos = 1 # At second byte of first character.
305
- # strio.read # => "\x82ест"
306
- # strio.pos = 2 # At first of second character.
307
- # strio.read # => "ест"
308
- #
309
- # strio = StringIO.new(TEXT)
310
- # strio.pos = 15
311
- # a = []
312
- # strio.each_line {|line| a.push(line) }
313
- # a # => ["nd line\n", "\n", "Fourth line\n", "Fifth line\n"]
314
- # strio.pos # => 47 ## End-of-stream.
315
- #
316
- # #### Position Before and After Writing
317
- # Each of these methods begins writing at the current position,
318
- # and advances the position to the end of the written substring:
319
- # * #putc: writes the given character.
320
- # * #write: writes the given objects as strings.
321
- # * [Kernel#puts](https://docs.ruby-lang.org/en/master/Kernel.html#method-i-pu
322
- # ts): writes given objects as strings, each followed by newline.
323
- # Examples:
324
- # strio = StringIO.new('foo')
325
- # strio.pos # => 0
326
- # strio.putc('b')
327
- # strio.string # => "boo"
328
- # strio.pos # => 1
329
- # strio.write('r')
330
- # strio.string # => "bro"
331
- # strio.pos # => 2
332
- # strio.puts('ew')
333
- # strio.string # => "brew\n"
334
- # strio.pos # => 5
335
- # strio.pos = 8
336
- # strio.write('foo')
337
- # strio.string # => "brew\n\u0000\u0000\u0000foo"
338
- # strio.pos # => 11
339
- #
340
- # Each of these methods writes *before* the current position, and decrements the
341
- # position
342
- # so that the written data is next to be read:
343
- # * #ungetbyte: unshifts the given byte.
344
- # * #ungetc: unshifts the given character.
345
- # Examples:
346
- # strio = StringIO.new('foo')
347
- # strio.pos = 2
348
- # strio.ungetc('x')
349
- # strio.pos # => 1
350
- # strio.string # => "fxo"
351
- # strio.ungetc('x')
352
- # strio.pos # => 0
353
- # strio.string # => "xxo"
354
- #
355
- # This method does not affect the position:
356
- # * #truncate: truncates the stream's string to the given size.
357
- # Examples:
358
- # strio = StringIO.new('foobar')
359
- # strio.pos # => 0
360
- # strio.truncate(3)
361
- # strio.string # => "foo"
362
- # strio.pos # => 0
363
- # strio.pos = 500
364
- # strio.truncate(0)
365
- # strio.string # => ""
366
- # strio.pos # => 500
367
- #
368
- # ### Line Number
369
- # A stream has a line number, which initially is zero:
370
- # * Method #lineno returns the line number.
371
- # * Method #lineno= sets the line number.
372
- # The line number can be affected by reading (but never by writing);
373
- # in general, the line number is incremented each time the record separator
374
- # (default: `"\n"`) is read.
375
- # Examples:
376
- # strio = StringIO.new(TEXT)
377
- # strio.string # => "First line\nSecond line\n\nFourth line\nFifth line\n"
378
- # strio.lineno # => 0
379
- # strio.gets # => "First line\n"
380
- # strio.lineno # => 1
381
- # strio.getc # => "S"
382
- # strio.lineno # => 1
383
- # strio.gets # => "econd line\n"
384
- # strio.lineno # => 2
385
- # strio.gets # => "\n"
386
- # strio.lineno # => 3
387
- # strio.gets # => "Fourth line\n"
388
- # strio.lineno # => 4
389
- #
390
- # Setting the position does not affect the line number:
391
- # strio.pos = 0
392
- # strio.lineno # => 4
393
- # strio.gets # => "First line\n"
394
- # strio.pos # => 11
395
- # strio.lineno # => 5
396
- #
397
- # And setting the line number does not affect the position:
398
- # strio.lineno = 10
399
- # strio.pos # => 11
400
- # strio.gets # => "Second line\n"
401
- # strio.lineno # => 11
402
- # strio.pos # => 23
403
- #
404
- # ### Open/Closed Streams
405
- # A new stream is open for either reading or writing, and may be open for both;
406
- # see [Read/Write Mode](rdoc-ref:StringIO@Read-2FWrite+Mode).
407
- # Each of these methods initializes the read/write mode for a new or re-opened
408
- # stream:
409
- # * ::new: returns a new stream.
410
- # * ::open: passes a new stream to the block.
411
- # * #reopen: re-initializes the stream.
412
- # Other relevant methods:
413
- # * #close: closes the stream for both reading and writing.
414
- # * #close_read: closes the stream for reading.
415
- # * #close_write: closes the stream for writing.
416
- # * #closed?: returns whether the stream is closed for both reading and
417
- # writing.
418
- # * #closed_read?: returns whether the stream is closed for reading.
419
- # * #closed_write?: returns whether the stream is closed for writing.
420
- # ### BOM (Byte Order Mark)
421
- # The string provided for ::new, ::open, or #reopen
422
- # may contain an optional [BOM](https://en.wikipedia.org/wiki/Byte_order_mark)
423
- # (byte order mark) at the beginning of the string;
424
- # the BOM can affect the stream's encoding.
425
- # The BOM (if provided):
426
- # * Is stored as part of the stream's string.
427
- # * Does *not* immediately affect the encoding.
428
- # * Is *initially* considered part of the stream.
429
- # utf8_bom = "\xEF\xBB\xBF"
430
- # string = utf8_bom + 'foo'
431
- # string.bytes # => [239, 187, 191, 102, 111, 111]
432
- # strio.string.bytes.take(3) # => [239, 187, 191] # The BOM.
433
- # strio = StringIO.new(string, 'rb')
434
- # strio.string.bytes # => [239, 187, 191, 102, 111, 111] # BOM is part of the stored string.
435
- # strio.external_encoding # => #<Encoding:BINARY (ASCII-8BIT)> # Default for a binary stream.
436
- # strio.gets # => "\xEF\xBB\xBFfoo" # BOM is part of the stream.
437
- #
438
- # You can call instance method #set_encoding_by_bom to "activate" the stored
439
- # BOM;
440
- # after doing so the BOM:
441
- # * Is *still* stored as part of the stream's string.
442
- # * *Determines* (and may have changed) the stream's encoding.
443
- # * Is *no longer* considered part of the stream.
444
- # strio.set_encoding_by_bom
445
- # strio.string.bytes # => [239, 187, 191, 102, 111, 111] # BOM is still part of the stored string.
446
- # strio.external_encoding # => #<Encoding:UTF-8> # The new encoding.
447
- # strio.rewind # => 0
448
- # strio.gets # => "foo" # BOM is not part of the stream.
7
+ # Examples on this page assume that StringIO has been required:
449
8
  #
450
- # ## Basic Stream IO
451
- # ### Basic Reading
452
- # You can read from the stream using these instance methods:
453
- # * #getbyte: reads and returns the next byte.
454
- # * #getc: reads and returns the next character.
455
- # * #gets: reads and returns all or part of the next line.
456
- # * #read: reads and returns all or part of the remaining data in the stream.
457
- # * #readlines: reads the remaining data the stream and returns an array of
458
- # its lines.
459
- # * [Kernel#readline](https://docs.ruby-lang.org/en/master/Kernel.html#method-
460
- # i-readline): like #gets, but raises an exception if at end-of-stream.
461
- # You can iterate over the stream using these instance methods:
462
- # * #each_byte: reads each remaining byte, passing it to the block.
463
- # * #each_char: reads each remaining character, passing it to the block.
464
- # * #each_codepoint: reads each remaining codepoint, passing it to the block.
465
- # * #each_line: reads all or part of each remaining line, passing the read
466
- # string to the block
467
- # This instance method is useful in a multi-threaded application:
468
- # * #pread: reads and returns all or part of the stream.
469
- # ### Basic Writing
470
- # You can write to the stream, advancing the position, using these instance
471
- # methods:
472
- # * #putc: writes a given character.
473
- # * #write: writes the given objects as strings.
474
- # * [Kernel#puts](https://docs.ruby-lang.org/en/master/Kernel.html#method-i-pu
475
- # ts) writes given objects as strings, each followed by newline.
476
- # You can "unshift" to the stream using these instance methods;
477
- # each writes *before* the current position, and decrements the position
478
- # so that the written data is next to be read.
479
- # * #ungetbyte: unshifts the given byte.
480
- # * #ungetc: unshifts the given character.
481
- # One more writing method:
482
- # * #truncate: truncates the stream's string to the given size.
483
- # ## Line IO
484
- # Reading:
485
- # * #gets: reads and returns the next line.
486
- # * [Kernel#readline](https://docs.ruby-lang.org/en/master/Kernel.html#method-
487
- # i-readline): like #gets, but raises an exception if at end-of-stream.
488
- # * #readlines: reads the remaining data the stream and returns an array of
489
- # its lines.
490
- # * #each_line: reads each remaining line, passing it to the block
491
- # Writing:
492
- # * [Kernel#puts](https://docs.ruby-lang.org/en/master/Kernel.html#method-i-pu
493
- # ts): writes given objects, each followed by newline.
494
- # ## Character IO
495
- # Reading:
496
- # * #each_char: reads each remaining character, passing it to the block.
497
- # * #getc: reads and returns the next character.
498
- # Writing:
499
- # * #putc: writes the given character.
500
- # * #ungetc.: unshifts the given character.
501
- # ## Byte IO
502
- # Reading:
503
- # * #each_byte: reads each remaining byte, passing it to the block.
504
- # * #getbyte: reads and returns the next byte.
505
- # Writing:
506
- # * #ungetbyte: unshifts the given byte.
507
- # ## Codepoint IO
508
- # Reading:
509
- # * #each_codepoint: reads each remaining codepoint, passing it to the block.
9
+ # require 'stringio'
510
10
  #
511
11
  class StringIO
512
12
  # <!--
513
13
  # rdoc-file=ext/stringio/stringio.c
514
14
  # - StringIO.new(string = '', mode = 'r+') -> new_stringio
515
15
  # -->
516
- # Returns a new StringIO instance formed from `string` and `mode`; the instance
517
- # should be closed when no longer needed:
518
- #
519
- # strio = StringIO.new
520
- # strio.string # => ""
521
- # strio.closed_read? # => false
522
- # strio.closed_write? # => false
523
- # strio.close
16
+ # Note that `mode` defaults to `'r'` if `string` is frozen.
524
17
  #
525
- # If `string` is frozen, the default `mode` is `'r'`:
18
+ # Returns a new StringIO instance formed from `string` and `mode`; see [Access
19
+ # Modes](rdoc-ref:File@Access+Modes):
526
20
  #
527
- # strio = StringIO.new('foo'.freeze)
528
- # strio.string # => "foo"
529
- # strio.closed_read? # => false
530
- # strio.closed_write? # => true
21
+ # strio = StringIO.new # => #<StringIO>
531
22
  # strio.close
532
23
  #
533
- # Argument `mode` must be a valid [Access Mode](rdoc-ref:File@Access+Modes),
534
- # which may be a string or an integer constant:
24
+ # The instance should be closed when no longer needed.
535
25
  #
536
- # StringIO.new('foo', 'w+')
537
- # StringIO.new('foo', File::RDONLY)
538
- #
539
- # Related: StringIO.open (passes the StringIO object to the block; closes the
540
- # object automatically on block exit).
26
+ # Related: StringIO.open (accepts block; closes automatically).
541
27
  #
542
28
  def initialize: (?String string, ?String? mode) -> void
543
29
 
544
30
  # <!--
545
31
  # rdoc-file=ext/stringio/stringio.c
546
- # - StringIO.open(string = '', mode = 'r+') -> new_stringio
547
- # - StringIO.open(string = '', mode = 'r+') {|strio| ... } -> object
32
+ # - StringIO.open(string = '', mode = 'r+') {|strio| ... }
548
33
  # -->
549
- # Creates new StringIO instance by calling `StringIO.new(string, mode)`.
34
+ # Note that `mode` defaults to `'r'` if `string` is frozen.
35
+ #
36
+ # Creates a new StringIO instance formed from `string` and `mode`; see [Access
37
+ # Modes](rdoc-ref:File@Access+Modes).
550
38
  #
551
- # With no block given, returns the new instance:
39
+ # With no block, returns the new instance:
552
40
  #
553
41
  # strio = StringIO.open # => #<StringIO>
554
42
  #
555
- # With a block given, calls the block with the new instance and returns the
556
- # block's value; closes the instance on block exit:
43
+ # With a block, calls the block with the new instance and returns the block's
44
+ # value; closes the instance on block exit.
557
45
  #
558
- # StringIO.open('foo') {|strio| strio.string.upcase } # => "FOO"
46
+ # StringIO.open {|strio| p strio }
47
+ # # => #<StringIO>
559
48
  #
560
49
  # Related: StringIO.new.
561
50
  #
@@ -568,7 +57,7 @@ class StringIO
568
57
  # - binmode -> self
569
58
  # -->
570
59
  # Sets the data mode in `self` to binary mode; see [Data
571
- # Mode](rdoc-ref:StringIO@Data+Mode).
60
+ # Mode](rdoc-ref:File@Data+Mode).
572
61
  #
573
62
  def binmode: () -> self
574
63
 
@@ -576,16 +65,11 @@ class StringIO
576
65
  # rdoc-file=ext/stringio/stringio.c
577
66
  # - close -> nil
578
67
  # -->
579
- # Closes `self` for both reading and writing; returns `nil`:
68
+ # Closes `self` for both reading and writing.
580
69
  #
581
- # strio = StringIO.new
582
- # strio.closed? # => false
583
- # strio.close # => nil
584
- # strio.closed? # => true
585
- # strio.read # Raises IOError: not opened for reading
586
- # strio.write # Raises IOError: not opened for writing
70
+ # Raises IOError if reading or writing is attempted.
587
71
  #
588
- # Related: StringIO#close_read, StringIO#close_write, StringIO.closed?.
72
+ # Related: StringIO#close_read, StringIO#close_write.
589
73
  #
590
74
  def close: () -> nil
591
75
 
@@ -593,15 +77,9 @@ class StringIO
593
77
  # rdoc-file=ext/stringio/stringio.c
594
78
  # - close_read -> nil
595
79
  # -->
596
- # Closes `self` for reading; closed-write setting remains unchanged; returns
597
- # `nil`:
80
+ # Closes `self` for reading; closed-write setting remains unchanged.
598
81
  #
599
- # strio = StringIO.new
600
- # strio.closed_read? # => false
601
- # strio.close_read # => nil
602
- # strio.closed_read? # => true
603
- # strio.closed_write? # => false
604
- # strio.read # Raises IOError: not opened for reading
82
+ # Raises IOError if reading is attempted.
605
83
  #
606
84
  # Related: StringIO#close, StringIO#close_write.
607
85
  #
@@ -611,17 +89,11 @@ class StringIO
611
89
  # rdoc-file=ext/stringio/stringio.c
612
90
  # - close_write -> nil
613
91
  # -->
614
- # Closes `self` for writing; closed-read setting remains unchanged; returns
615
- # `nil`:
92
+ # Closes `self` for writing; closed-read setting remains unchanged.
616
93
  #
617
- # strio = StringIO.new
618
- # strio.closed_write? # => false
619
- # strio.close_write # => nil
620
- # strio.closed_write? # => true
621
- # strio.closed_read? # => false
622
- # strio.write('foo') # Raises IOError: not opened for writing
94
+ # Raises IOError if writing is attempted.
623
95
  #
624
- # Related: StringIO#close, StringIO#close_read, StringIO#closed_write?.
96
+ # Related: StringIO#close, StringIO#close_read.
625
97
  #
626
98
  def close_write: () -> nil
627
99
 
@@ -629,16 +101,8 @@ class StringIO
629
101
  # rdoc-file=ext/stringio/stringio.c
630
102
  # - closed? -> true or false
631
103
  # -->
632
- # Returns whether `self` is closed for both reading and writing:
633
- #
634
- # strio = StringIO.new
635
- # strio.closed? # => false # Open for reading and writing.
636
- # strio.close_read
637
- # strio.closed? # => false # Still open for writing.
638
- # strio.close_write
639
- # strio.closed? # => true # Now closed for both.
640
- #
641
- # Related: StringIO.closed_read?, StringIO.closed_write?.
104
+ # Returns `true` if `self` is closed for both reading and writing, `false`
105
+ # otherwise.
642
106
  #
643
107
  def closed?: () -> bool
644
108
 
@@ -646,14 +110,7 @@ class StringIO
646
110
  # rdoc-file=ext/stringio/stringio.c
647
111
  # - closed_read? -> true or false
648
112
  # -->
649
- # Returns whether `self` is closed for reading:
650
- #
651
- # strio = StringIO.new
652
- # strio.closed_read? # => false
653
- # strio.close_read
654
- # strio.closed_read? # => true
655
- #
656
- # Related: StringIO#closed?, StringIO#closed_write?, StringIO#close_read.
113
+ # Returns `true` if `self` is closed for reading, `false` otherwise.
657
114
  #
658
115
  def closed_read?: () -> bool
659
116
 
@@ -661,14 +118,7 @@ class StringIO
661
118
  # rdoc-file=ext/stringio/stringio.c
662
119
  # - closed_write? -> true or false
663
120
  # -->
664
- # Returns whether `self` is closed for writing:
665
- #
666
- # strio = StringIO.new
667
- # strio.closed_write? # => false
668
- # strio.close_write
669
- # strio.closed_write? # => true
670
- #
671
- # Related: StringIO#close_write, StringIO#closed?, StringIO#closed_read?.
121
+ # Returns `true` if `self` is closed for writing, `false` otherwise.
672
122
  #
673
123
  def closed_write?: () -> bool
674
124
 
@@ -678,137 +128,8 @@ class StringIO
678
128
  # - each_line(limit, chomp: false) {|line| ... } -> self
679
129
  # - each_line(sep, limit, chomp: false) {|line| ... } -> self
680
130
  # -->
681
- # With a block given calls the block with each remaining line (see "Position"
682
- # below) in the stream;
683
- # returns `self`.
684
- # Leaves stream position at end-of-stream.
685
- # **No Arguments**
686
- # With no arguments given,
687
- # reads lines using the default record separator
688
- # (global variable `$/`, whose initial value is `"\n"`).
689
- # strio = StringIO.new(TEXT)
690
- # strio.each_line {|line| p line }
691
- # strio.eof? # => true
692
- #
693
- # Output:
694
- # "First line\n"
695
- # "Second line\n"
696
- # "\n"
697
- # "Fourth line\n"
698
- # "Fifth line\n"
699
- #
700
- # **Argument `sep`**
701
- # With only string argument `sep` given,
702
- # reads lines using that string as the record separator:
703
- # strio = StringIO.new(TEXT)
704
- # strio.each_line(' ') {|line| p line }
705
- #
706
- # Output:
707
- # "First "
708
- # "line\nSecond "
709
- # "line\n\nFourth "
710
- # "line\nFifth "
711
- # "line\n"
712
- #
713
- # **Argument `limit`**
714
- # With only integer argument `limit` given,
715
- # reads lines using the default record separator;
716
- # also limits the size (in characters) of each line to the given limit:
717
- # strio = StringIO.new(TEXT)
718
- # strio.each_line(10) {|line| p line }
719
- #
720
- # Output:
721
- # "First line"
722
- # "\n"
723
- # "Second lin"
724
- # "e\n"
725
- # "\n"
726
- # "Fourth lin"
727
- # "e\n"
728
- # "Fifth line"
729
- # "\n"
730
- #
731
- # **Arguments `sep` and `limit`**
732
- # With arguments `sep` and `limit` both given,
733
- # honors both:
734
- # strio = StringIO.new(TEXT)
735
- # strio.each_line(' ', 10) {|line| p line }
736
- #
737
- # Output:
738
- # "First "
739
- # "line\nSecon"
740
- # "d "
741
- # "line\n\nFour"
742
- # "th "
743
- # "line\nFifth"
744
- # " "
745
- # "line\n"
746
- #
747
- # **Position**
748
- # As stated above, method `each` *remaining* line in the stream.
749
- # In the examples above each `strio` object starts with its position at
750
- # beginning-of-stream;
751
- # but in other cases the position may be anywhere (see StringIO#pos):
752
- # strio = StringIO.new(TEXT)
753
- # strio.pos = 30 # Set stream position to character 30.
754
- # strio.each_line {|line| p line }
755
- #
756
- # Output:
757
- # " line\n"
758
- # "Fifth line\n"
759
- #
760
- # In all the examples above, the stream position is at the beginning of a
761
- # character;
762
- # in other cases, that need not be so:
763
- # s = 'こんにちは' # Five 3-byte characters.
764
- # strio = StringIO.new(s)
765
- # strio.pos = 3 # At beginning of second character.
766
- # strio.each_line {|line| p line }
767
- # strio.pos = 4 # At second byte of second character.
768
- # strio.each_line {|line| p line }
769
- # strio.pos = 5 # At third byte of second character.
770
- # strio.each_line {|line| p line }
771
- #
772
- # Output:
773
- # "んにちは"
774
- # "\x82\x93にちは"
775
- # "\x93にちは"
776
- #
777
- # **Special Record Separators**
778
- # Like some methods in class `IO`, StringIO.each honors two special record
779
- # separators;
780
- # see [Special Line
781
- # Separators](https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Specia
782
- # l+Line+Separator+Values).
783
- # strio = StringIO.new(TEXT)
784
- # strio.each_line('') {|line| p line } # Read as paragraphs (separated by blank lines).
785
- #
786
- # Output:
787
- # "First line\nSecond line\n\n"
788
- # "Fourth line\nFifth line\n"
789
- #
790
- # strio = StringIO.new(TEXT)
791
- # strio.each_line(nil) {|line| p line } # "Slurp"; read it all.
792
- #
793
- # Output:
794
- # "First line\nSecond line\n\nFourth line\nFifth line\n"
795
- #
796
- # **Keyword Argument `chomp`**
797
- # With keyword argument `chomp` given as `true` (the default is `false`),
798
- # removes trailing newline (if any) from each line:
799
- # strio = StringIO.new(TEXT)
800
- # strio.each_line(chomp: true) {|line| p line }
801
- #
802
- # Output:
803
- # "First line"
804
- # "Second line"
805
- # ""
806
- # "Fourth line"
807
- # "Fifth line"
808
- #
809
- # With no block given, returns a new
810
- # [Enumerator](https://docs.ruby-lang.org/en/master/Enumerator.html).
811
- # Related: StringIO.each_byte, StringIO.each_char, StringIO.each_codepoint.
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).
812
133
  #
813
134
  def each: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self
814
135
  | (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self]
@@ -818,83 +139,21 @@ class StringIO
818
139
  # - each_byte {|byte| ... } -> self
819
140
  # -->
820
141
  # With a block given, calls the block with each remaining byte in the stream;
821
- # positions the stream at end-of-file; returns `self`:
822
- #
823
- # bytes = []
824
- # strio = StringIO.new('hello') # Five 1-byte characters.
825
- # strio.each_byte {|byte| bytes.push(byte) }
826
- # strio.eof? # => true
827
- # bytes # => [104, 101, 108, 108, 111]
828
- # bytes = []
829
- # strio = StringIO.new('тест') # Four 2-byte characters.
830
- # strio.each_byte {|byte| bytes.push(byte) }
831
- # bytes # => [209, 130, 208, 181, 209, 129, 209, 130]
832
- # bytes = []
833
- # strio = StringIO.new('こんにちは') # Five 3-byte characters.
834
- # strio.each_byte {|byte| bytes.push(byte) }
835
- # bytes # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
142
+ # see [Byte IO](rdoc-ref:IO@Byte+IO).
836
143
  #
837
- # The position in the stream matters:
838
- #
839
- # bytes = []
840
- # strio = StringIO.new('こんにちは')
841
- # strio.getc # => "こ"
842
- # strio.pos # => 3 # 3-byte character was read.
843
- # strio.each_byte {|byte| bytes.push(byte) }
844
- # bytes # => [227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
845
- #
846
- # If at end-of-file, does not call the block:
847
- #
848
- # strio.eof? # => true
849
- # strio.each_byte {|byte| fail 'Boo!' }
850
- # strio.eof? # => true
851
- #
852
- # With no block given, returns a new [Enumerator](rdoc-ref:Enumerator).
853
- #
854
- # Related: StringIO#each_char, StringIO#each_codepoint, StringIO#each_line.
144
+ # With no block given, returns an enumerator.
855
145
  #
856
146
  def each_byte: () { (Integer arg0) -> untyped } -> self
857
147
  | () -> ::Enumerator[Integer, self]
858
148
 
859
149
  # <!--
860
150
  # rdoc-file=ext/stringio/stringio.c
861
- # - each_char {|char| ... } -> self
151
+ # - each_char {|c| ... } -> self
862
152
  # -->
863
153
  # With a block given, calls the block with each remaining character in the
864
- # stream; positions the stream at end-of-file; returns `self`:
865
- #
866
- # chars = []
867
- # strio = StringIO.new('hello')
868
- # strio.each_char {|char| chars.push(char) }
869
- # strio.eof? # => true
870
- # chars # => ["h", "e", "l", "l", "o"]
871
- # chars = []
872
- # strio = StringIO.new('тест')
873
- # strio.each_char {|char| chars.push(char) }
874
- # chars # => ["т", "е", "с", "т"]
875
- # chars = []
876
- # strio = StringIO.new('こんにちは')
877
- # strio.each_char {|char| chars.push(char) }
878
- # chars # => ["こ", "ん", "に", "ち", "は"]
879
- #
880
- # Stream position matters:
881
- #
882
- # chars = []
883
- # strio = StringIO.new('こんにちは')
884
- # strio.getc # => "こ"
885
- # strio.pos # => 3 # 3-byte character was read.
886
- # strio.each_char {|char| chars.push(char) }
887
- # chars # => ["ん", "に", "ち", "は"]
888
- #
889
- # When at end-of-stream does not call the block:
890
- #
891
- # strio.eof? # => true
892
- # strio.each_char {|char| fail 'Boo!' }
893
- # strio.eof? # => true
154
+ # stream; see [Character IO](rdoc-ref:IO@Character+IO).
894
155
  #
895
- # With no block given, returns a new [Enumerator](rdoc-ref:Enumerator).
896
- #
897
- # Related: StringIO#each_byte, StringIO#each_codepoint, StringIO#each_line.
156
+ # With no block given, returns an enumerator.
898
157
  #
899
158
  def each_char: () { (String arg0) -> untyped } -> self
900
159
  | () -> ::Enumerator[String, self]
@@ -903,43 +162,10 @@ class StringIO
903
162
  # rdoc-file=ext/stringio/stringio.c
904
163
  # - each_codepoint {|codepoint| ... } -> self
905
164
  # -->
906
- # With a block given, calls the block with each successive codepoint from self;
907
- # sets the position to end-of-stream; returns `self`.
908
- #
909
- # Each codepoint is the integer value for a character; returns self:
910
- #
911
- # codepoints = []
912
- # strio = StringIO.new('hello')
913
- # strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
914
- # strio.eof? # => true
915
- # codepoints # => [104, 101, 108, 108, 111]
916
- # codepoints = []
917
- # strio = StringIO.new('тест')
918
- # strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
919
- # codepoints # => [1090, 1077, 1089, 1090]
920
- # codepoints = []
921
- # strio = StringIO.new('こんにちは')
922
- # strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
923
- # codepoints # => [12371, 12435, 12395, 12385, 12399]
924
- #
925
- # Position in the stream matters:
926
- #
927
- # codepoints = []
928
- # strio = StringIO.new('こんにちは')
929
- # strio.getc # => "こ"
930
- # strio.pos # => 3
931
- # strio.each_codepoint {|codepoint| codepoints.push(codepoint) }
932
- # codepoints # => [12435, 12395, 12385, 12399]
165
+ # With a block given, calls the block with each remaining codepoint in the
166
+ # stream; see [Codepoint IO](rdoc-ref:IO@Codepoint+IO).
933
167
  #
934
- # When at end-of-stream, the block is not called:
935
- #
936
- # strio.eof? # => true
937
- # strio.each_codepoint {|codepoint| fail 'Boo!' }
938
- # strio.eof? # => true
939
- #
940
- # With no block given, returns a new [Enumerator](rdoc-ref:Enumerator).
941
- #
942
- # Related: StringIO#each_byte, StringIO#each_char, StringIO#each_line.
168
+ # With no block given, returns an enumerator.
943
169
  #
944
170
  def each_codepoint: () { (Integer arg0) -> untyped } -> self
945
171
  | () -> ::Enumerator[Integer, self]
@@ -948,18 +174,10 @@ class StringIO
948
174
  # rdoc-file=ext/stringio/stringio.c
949
175
  # - eof? -> true or false
950
176
  # -->
951
- # Returns whether `self` is positioned at end-of-stream:
177
+ # Returns `true` if positioned at end-of-stream, `false` otherwise; see
178
+ # [Position](rdoc-ref:IO@Position).
952
179
  #
953
- # strio = StringIO.new('foo')
954
- # strio.pos # => 0
955
- # strio.eof? # => false
956
- # strio.read # => "foo"
957
- # strio.pos # => 3
958
- # strio.eof? # => true
959
- # strio.close_read
960
- # strio.eof? # Raises IOError: not opened for reading
961
- #
962
- # Related: StringIO#pos.
180
+ # Raises IOError if the stream is not opened for reading.
963
181
  #
964
182
  def eof: () -> bool
965
183
 
@@ -975,7 +193,7 @@ class StringIO
975
193
  # rdoc-file=ext/stringio/stringio.c
976
194
  # - fileno()
977
195
  # -->
978
- # Returns `nil`; for compatibility with IO.
196
+ # Returns `nil`. Just for compatibility to IO.
979
197
  #
980
198
  def fileno: () -> nil
981
199
 
@@ -983,7 +201,7 @@ class StringIO
983
201
  # rdoc-file=ext/stringio/stringio.c
984
202
  # - flush()
985
203
  # -->
986
- # Returns `self`; for compatibility with IO.
204
+ # Returns an object itself. Just for compatibility to IO.
987
205
  #
988
206
  def flush: () -> self
989
207
 
@@ -991,86 +209,25 @@ class StringIO
991
209
  # rdoc-file=ext/stringio/stringio.c
992
210
  # - fsync()
993
211
  # -->
994
- # Returns 0; for compatibility with IO.
212
+ # Returns 0. Just for compatibility to IO.
995
213
  #
996
214
  def fsync: () -> Integer?
997
215
 
998
216
  # <!--
999
217
  # rdoc-file=ext/stringio/stringio.c
1000
- # - getbyte -> integer or nil
218
+ # - getbyte -> byte or nil
1001
219
  # -->
1002
- # Reads and returns the next integer byte (not character) from the stream:
1003
- #
1004
- # s = 'foo'
1005
- # s.bytes # => [102, 111, 111]
1006
- # strio = StringIO.new(s)
1007
- # strio.getbyte # => 102
1008
- # strio.getbyte # => 111
1009
- # strio.getbyte # => 111
1010
- #
1011
- # Returns `nil` if at end-of-stream:
1012
- #
1013
- # strio.eof? # => true
1014
- # strio.getbyte # => nil
1015
- #
1016
- # Returns a byte, not a character:
1017
- #
1018
- # s = 'Привет'
1019
- # s.bytes
1020
- # # => [208, 159, 209, 128, 208, 184, 208, 178, 208, 181, 209, 130]
1021
- # strio = StringIO.new(s)
1022
- # strio.getbyte # => 208
1023
- # strio.getbyte # => 159
1024
- #
1025
- # s = 'こんにちは'
1026
- # s.bytes
1027
- # # => [227, 129, 147, 227, 130, 147, 227, 129, 171, 227, 129, 161, 227, 129, 175]
1028
- # strio = StringIO.new(s)
1029
- # strio.getbyte # => 227
1030
- # strio.getbyte # => 129
1031
- #
1032
- # Related: #each_byte, #ungetbyte, #getc.
220
+ # Reads and returns the next 8-bit byte from the stream; see [Byte
221
+ # IO](rdoc-ref:IO@Byte+IO).
1033
222
  #
1034
223
  def getbyte: () -> Integer?
1035
224
 
1036
225
  # <!--
1037
226
  # rdoc-file=ext/stringio/stringio.c
1038
- # - getc -> character, byte, or nil
227
+ # - getc -> character or nil
1039
228
  # -->
1040
- # Reads and returns the next character (or byte; see below) from the stream:
1041
- #
1042
- # strio = StringIO.new('foo')
1043
- # strio.getc # => "f"
1044
- # strio.getc # => "o"
1045
- # strio.getc # => "o"
1046
- #
1047
- # Returns `nil` if at end-of-stream:
1048
- #
1049
- # strio.eof? # => true
1050
- # strio.getc # => nil
1051
- #
1052
- # Returns characters, not bytes:
1053
- #
1054
- # strio = StringIO.new('Привет')
1055
- # strio.getc # => "П"
1056
- # strio.getc # => "р"
1057
- #
1058
- # strio = StringIO.new('こんにちは')
1059
- # strio.getc # => "こ"
1060
- # strio.getc # => "ん"
1061
- #
1062
- # In each of the examples above, the stream is positioned at the beginning of a
1063
- # character; in other cases that need not be true:
1064
- #
1065
- # strio = StringIO.new('こんにちは') # Five 3-byte characters.
1066
- # strio.pos = 3 # => 3 # At beginning of second character; returns character.
1067
- # strio.getc # => "ん"
1068
- # strio.pos = 4 # => 4 # At second byte of second character; returns byte.
1069
- # strio.getc # => "\x82"
1070
- # strio.pos = 5 # => 5 # At third byte of second character; returns byte.
1071
- # strio.getc # => "\x93"
1072
- #
1073
- # Related: #getbyte, #putc, #ungetc.
229
+ # Reads and returns the next character from the stream; see [Character
230
+ # IO](rdoc-ref:IO@Character+IO).
1074
231
  #
1075
232
  def getc: () -> String?
1076
233
 
@@ -1080,131 +237,26 @@ class StringIO
1080
237
  # - gets(limit, chomp: false) -> string or nil
1081
238
  # - gets(sep, limit, chomp: false) -> string or nil
1082
239
  # -->
1083
- # Reads and returns a line from the stream; returns `nil` if at end-of-stream.
1084
- #
1085
- # Side effects:
1086
- #
1087
- # * Increments stream position by the number of bytes read.
1088
- # * Assigns the return value to global variable `$_`.
1089
- #
1090
- # With no arguments given, reads a line using the default record separator
1091
- # (global variable `$/`,* whose initial value is `"\n"`):
1092
- #
1093
- # strio = StringIO.new(TEXT)
1094
- # strio.pos # => 0
1095
- # strio.gets # => "First line\n"
1096
- # strio.pos # => 11
1097
- # $_ # => "First line\n"
1098
- # strio.gets # => "Second line\n"
1099
- # strio.read # => "\nFourth line\nFifth line\n"
1100
- # strio.eof? # => true
1101
- # strio.gets # => nil
1102
- #
1103
- # strio = StringIO.new('Привет') # Six 2-byte characters
1104
- # strio.pos # => 0
1105
- # strio.gets # => "Привет"
1106
- # strio.pos # => 12
1107
- #
1108
- # **Argument `sep`**
1109
- #
1110
- # With only string argument `sep` given, reads a line using that string as the
1111
- # record separator:
1112
- #
1113
- # strio = StringIO.new(TEXT)
1114
- # strio.gets(' ') # => "First "
1115
- # strio.gets(' ') # => "line\nSecond "
1116
- # strio.gets(' ') # => "line\n\nFourth "
1117
- #
1118
- # **Argument `limit`**
1119
- #
1120
- # With only integer argument `limit` given, reads a line using the default
1121
- # record separator; limits the size (in characters) of each line to the given
1122
- # limit:
1123
- #
1124
- # strio = StringIO.new(TEXT)
1125
- # strio.gets(10) # => "First line"
1126
- # strio.gets(10) # => "\n"
1127
- # strio.gets(10) # => "Second lin"
1128
- # strio.gets(10) # => "e\n"
1129
- #
1130
- # **Arguments `sep` and `limit`**
1131
- #
1132
- # With arguments `sep` and `limit` both given, honors both:
1133
- #
1134
- # strio = StringIO.new(TEXT)
1135
- # strio.gets(' ', 10) # => "First "
1136
- # strio.gets(' ', 10) # => "line\nSecon"
1137
- # strio.gets(' ', 10) # => "d "
1138
- #
1139
- # **Position**
1140
- #
1141
- # As stated above, method `gets` reads and returns the next line in the stream.
1142
- #
1143
- # In the examples above each `strio` object starts with its position at
1144
- # beginning-of-stream; but in other cases the position may be anywhere:
1145
- #
1146
- # strio = StringIO.new(TEXT)
1147
- # strio.pos = 12
1148
- # strio.gets # => "econd line\n"
1149
- #
1150
- # The position need not be at a character boundary:
1151
- #
1152
- # strio = StringIO.new('Привет') # Six 2-byte characters.
1153
- # strio.pos = 2 # At beginning of second character.
1154
- # strio.gets # => "ривет"
1155
- # strio.pos = 3 # In middle of second character.
1156
- # strio.gets # => "\x80ивет"
1157
- #
1158
- # **Special Record Separators**
1159
- #
1160
- # Like some methods in class IO, method `gets` honors two special record
1161
- # separators; see [Special Line
1162
- # Separators](https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Specia
1163
- # l+Line+Separator+Values):
1164
- #
1165
- # strio = StringIO.new(TEXT)
1166
- # strio.gets('') # Read "paragraph" (up to empty line).
1167
- # # => "First line\nSecond line\n\n"
1168
- #
1169
- # strio = StringIO.new(TEXT)
1170
- # strio.gets(nil) # "Slurp": read all.
1171
- # # => "First line\nSecond line\n\nFourth line\nFifth line\n"
1172
- #
1173
- # **Keyword Argument `chomp`**
1174
- #
1175
- # With keyword argument `chomp` given as `true` (the default is `false`),
1176
- # removes the trailing newline (if any) from the returned line:
1177
- #
1178
- # strio = StringIO.new(TEXT)
1179
- # strio.gets # => "First line\n"
1180
- # strio.gets(chomp: true) # => "Second line"
1181
- #
1182
- # Related: #each_line, #readlines, [Kernel#puts](rdoc-ref:Kernel#puts).
240
+ # Reads and returns a line from the stream; assigns the return value to `$_`;
241
+ # see [Line IO](rdoc-ref:IO@Line+IO).
1183
242
  #
1184
243
  def gets: (?String sep, ?Integer limit, ?chomp: boolish) -> String?
1185
244
 
1186
245
  # <!--
1187
246
  # rdoc-file=ext/stringio/stringio.c
1188
- # - internal_encoding -> nil
247
+ # - strio.internal_encoding => encoding
1189
248
  # -->
1190
- # Returns `nil`; for compatibility with IO.
249
+ # Returns the Encoding of the internal string if conversion is specified.
250
+ # Otherwise returns `nil`.
1191
251
  #
1192
252
  def internal_encoding: () -> Encoding
1193
253
 
1194
254
  # <!--
1195
255
  # rdoc-file=ext/stringio/stringio.c
1196
- # - external_encoding -> encoding or nil
256
+ # - strio.external_encoding => encoding
1197
257
  # -->
1198
- # Returns an Encoding object that represents the encoding of the string; see
1199
- # [Encodings](rdoc-ref:StringIO@Encodings):
1200
- #
1201
- # strio = StringIO.new('foo')
1202
- # strio.external_encoding # => #<Encoding:UTF-8>
1203
- #
1204
- # Returns `nil` if `self` has no string and is in write mode:
1205
- #
1206
- # strio = StringIO.new(nil, 'w+')
1207
- # strio.external_encoding # => nil
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`.
1208
260
  #
1209
261
  def external_encoding: () -> Encoding
1210
262
 
@@ -1212,7 +264,7 @@ class StringIO
1212
264
  # rdoc-file=ext/stringio/stringio.c
1213
265
  # - isatty()
1214
266
  # -->
1215
- # Returns `false`; for compatibility with IO.
267
+ # Returns `false`. Just for compatibility to IO.
1216
268
  #
1217
269
  def isatty: () -> bool
1218
270
 
@@ -1221,7 +273,7 @@ class StringIO
1221
273
  # - lineno -> current_line_number
1222
274
  # -->
1223
275
  # Returns the current line number in `self`; see [Line
1224
- # Number](rdoc-ref:StringIO@Line+Number).
276
+ # Number](rdoc-ref:IO@Line+Number).
1225
277
  #
1226
278
  def lineno: () -> Integer
1227
279
 
@@ -1230,7 +282,7 @@ class StringIO
1230
282
  # - lineno = new_line_number -> new_line_number
1231
283
  # -->
1232
284
  # Sets the current line number in `self` to the given `new_line_number`; see
1233
- # [Line Number](rdoc-ref:StringIO@Line+Number).
285
+ # [Line Number](rdoc-ref:IO@Line+Number).
1234
286
  #
1235
287
  def lineno=: (Integer arg0) -> Integer
1236
288
 
@@ -1238,7 +290,7 @@ class StringIO
1238
290
  # rdoc-file=ext/stringio/stringio.c
1239
291
  # - pid()
1240
292
  # -->
1241
- # Returns `nil`; for compatibility with IO.
293
+ # Returns `nil`. Just for compatibility to IO.
1242
294
  #
1243
295
  def pid: () -> nil
1244
296
 
@@ -1246,8 +298,7 @@ class StringIO
1246
298
  # rdoc-file=ext/stringio/stringio.c
1247
299
  # - pos -> stream_position
1248
300
  # -->
1249
- # Returns the current position (in bytes); see
1250
- # [Position](rdoc-ref:StringIO@Position).
301
+ # Returns the current position (in bytes); see [Position](rdoc-ref:IO@Position).
1251
302
  #
1252
303
  def pos: () -> Integer
1253
304
 
@@ -1255,8 +306,7 @@ class StringIO
1255
306
  # rdoc-file=ext/stringio/stringio.c
1256
307
  # - pos = new_position -> new_position
1257
308
  # -->
1258
- # Sets the current position (in bytes); see
1259
- # [Position](rdoc-ref:StringIO@Position).
309
+ # Sets the current position (in bytes); see [Position](rdoc-ref:IO@Position).
1260
310
  #
1261
311
  def pos=: (Integer arg0) -> Integer
1262
312
 
@@ -1341,8 +391,8 @@ class StringIO
1341
391
  # rdoc-file=ext/stringio/stringio.c
1342
392
  # - seek(offset, whence = SEEK_SET) -> 0
1343
393
  # -->
1344
- # Sets the position to the given integer `offset` (in bytes), with respect to a
1345
- # given constant `whence`; see [IO#seek](rdoc-ref:IO#seek).
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).
1346
396
  #
1347
397
  def seek: (Integer amount, ?Integer whence) -> Integer
1348
398
 
@@ -1382,7 +432,7 @@ class StringIO
1382
432
  # rdoc-file=ext/stringio/stringio.c
1383
433
  # - string = other_string -> other_string
1384
434
  # -->
1385
- # Replaces the stored string with `other_string`, and sets the position to zero;
435
+ # Assigns the underlying string as `other_string`, and sets position to zero;
1386
436
  # returns `other_string`:
1387
437
  #
1388
438
  # StringIO.open('foo') do |strio|
@@ -1396,19 +446,16 @@ class StringIO
1396
446
  # "foo"
1397
447
  # "bar"
1398
448
  #
1399
- # Related: StringIO#string (returns the stored string).
449
+ # Related: StringIO#string (returns the underlying string).
1400
450
  #
1401
451
  def string=: (String str) -> String
1402
452
 
1403
453
  # <!--
1404
454
  # rdoc-file=ext/stringio/stringio.c
1405
- # - size -> integer
455
+ # - strio.length -> integer
456
+ # - strio.size -> integer
1406
457
  # -->
1407
- # Returns the number of bytes in the string in `self`:
1408
- #
1409
- # StringIO.new('hello').size # => 5 # Five 1-byte characters.
1410
- # StringIO.new('тест').size # => 8 # Four 2-byte characters.
1411
- # StringIO.new('こんにちは').size # => 15 # Five 3-byte characters.
458
+ # Returns the size of the buffer string.
1412
459
  #
1413
460
  def size: () -> Integer
1414
461
 
@@ -1436,8 +483,7 @@ class StringIO
1436
483
  # rdoc-file=ext/stringio/stringio.c
1437
484
  # - pos -> stream_position
1438
485
  # -->
1439
- # Returns the current position (in bytes); see
1440
- # [Position](rdoc-ref:StringIO@Position).
486
+ # Returns the current position (in bytes); see [Position](rdoc-ref:IO@Position).
1441
487
  #
1442
488
  def tell: () -> Integer
1443
489
 
@@ -1451,7 +497,7 @@ class StringIO
1451
497
  def truncate: (Integer) -> 0
1452
498
 
1453
499
  # <!-- rdoc-file=ext/stringio/stringio.c -->
1454
- # Returns `false`; for compatibility with IO.
500
+ # Returns `false`. Just for compatibility to IO.
1455
501
  #
1456
502
  def tty?: () -> bool
1457
503
 
@@ -1500,154 +546,17 @@ class StringIO
1500
546
  | () -> ::Enumerator[Integer, self]
1501
547
 
1502
548
  # <!-- rdoc-file=ext/stringio/stringio.c -->
1503
- # With a block given calls the block with each remaining line (see "Position"
1504
- # below) in the stream;
1505
- # returns `self`.
1506
- # Leaves stream position at end-of-stream.
1507
- # **No Arguments**
1508
- # With no arguments given,
1509
- # reads lines using the default record separator
1510
- # (global variable `$/`, whose initial value is `"\n"`).
1511
- # strio = StringIO.new(TEXT)
1512
- # strio.each_line {|line| p line }
1513
- # strio.eof? # => true
1514
- #
1515
- # Output:
1516
- # "First line\n"
1517
- # "Second line\n"
1518
- # "\n"
1519
- # "Fourth line\n"
1520
- # "Fifth line\n"
1521
- #
1522
- # **Argument `sep`**
1523
- # With only string argument `sep` given,
1524
- # reads lines using that string as the record separator:
1525
- # strio = StringIO.new(TEXT)
1526
- # strio.each_line(' ') {|line| p line }
1527
- #
1528
- # Output:
1529
- # "First "
1530
- # "line\nSecond "
1531
- # "line\n\nFourth "
1532
- # "line\nFifth "
1533
- # "line\n"
1534
- #
1535
- # **Argument `limit`**
1536
- # With only integer argument `limit` given,
1537
- # reads lines using the default record separator;
1538
- # also limits the size (in characters) of each line to the given limit:
1539
- # strio = StringIO.new(TEXT)
1540
- # strio.each_line(10) {|line| p line }
1541
- #
1542
- # Output:
1543
- # "First line"
1544
- # "\n"
1545
- # "Second lin"
1546
- # "e\n"
1547
- # "\n"
1548
- # "Fourth lin"
1549
- # "e\n"
1550
- # "Fifth line"
1551
- # "\n"
1552
- #
1553
- # **Arguments `sep` and `limit`**
1554
- # With arguments `sep` and `limit` both given,
1555
- # honors both:
1556
- # strio = StringIO.new(TEXT)
1557
- # strio.each_line(' ', 10) {|line| p line }
1558
- #
1559
- # Output:
1560
- # "First "
1561
- # "line\nSecon"
1562
- # "d "
1563
- # "line\n\nFour"
1564
- # "th "
1565
- # "line\nFifth"
1566
- # " "
1567
- # "line\n"
1568
- #
1569
- # **Position**
1570
- # As stated above, method `each` *remaining* line in the stream.
1571
- # In the examples above each `strio` object starts with its position at
1572
- # beginning-of-stream;
1573
- # but in other cases the position may be anywhere (see StringIO#pos):
1574
- # strio = StringIO.new(TEXT)
1575
- # strio.pos = 30 # Set stream position to character 30.
1576
- # strio.each_line {|line| p line }
1577
- #
1578
- # Output:
1579
- # " line\n"
1580
- # "Fifth line\n"
1581
- #
1582
- # In all the examples above, the stream position is at the beginning of a
1583
- # character;
1584
- # in other cases, that need not be so:
1585
- # s = 'こんにちは' # Five 3-byte characters.
1586
- # strio = StringIO.new(s)
1587
- # strio.pos = 3 # At beginning of second character.
1588
- # strio.each_line {|line| p line }
1589
- # strio.pos = 4 # At second byte of second character.
1590
- # strio.each_line {|line| p line }
1591
- # strio.pos = 5 # At third byte of second character.
1592
- # strio.each_line {|line| p line }
1593
- #
1594
- # Output:
1595
- # "んにちは"
1596
- # "\x82\x93にちは"
1597
- # "\x93にちは"
1598
- #
1599
- # **Special Record Separators**
1600
- # Like some methods in class `IO`, StringIO.each honors two special record
1601
- # separators;
1602
- # see [Special Line
1603
- # Separators](https://docs.ruby-lang.org/en/master/IO.html#class-IO-label-Specia
1604
- # l+Line+Separator+Values).
1605
- # strio = StringIO.new(TEXT)
1606
- # strio.each_line('') {|line| p line } # Read as paragraphs (separated by blank lines).
1607
- #
1608
- # Output:
1609
- # "First line\nSecond line\n\n"
1610
- # "Fourth line\nFifth line\n"
1611
- #
1612
- # strio = StringIO.new(TEXT)
1613
- # strio.each_line(nil) {|line| p line } # "Slurp"; read it all.
1614
- #
1615
- # Output:
1616
- # "First line\nSecond line\n\nFourth line\nFifth line\n"
1617
- #
1618
- # **Keyword Argument `chomp`**
1619
- # With keyword argument `chomp` given as `true` (the default is `false`),
1620
- # removes trailing newline (if any) from each line:
1621
- # strio = StringIO.new(TEXT)
1622
- # strio.each_line(chomp: true) {|line| p line }
1623
- #
1624
- # Output:
1625
- # "First line"
1626
- # "Second line"
1627
- # ""
1628
- # "Fourth line"
1629
- # "Fifth line"
1630
- #
1631
- # With no block given, returns a new
1632
- # [Enumerator](https://docs.ruby-lang.org/en/master/Enumerator.html).
1633
- # Related: StringIO.each_byte, StringIO.each_char, StringIO.each_codepoint.
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).
1634
551
  #
1635
552
  def each_line: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self
1636
553
  | (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self]
1637
554
 
1638
555
  # <!-- rdoc-file=ext/stringio/stringio.c -->
1639
- # Returns whether `self` is positioned at end-of-stream:
1640
- #
1641
- # strio = StringIO.new('foo')
1642
- # strio.pos # => 0
1643
- # strio.eof? # => false
1644
- # strio.read # => "foo"
1645
- # strio.pos # => 3
1646
- # strio.eof? # => true
1647
- # strio.close_read
1648
- # strio.eof? # Raises IOError: not opened for reading
1649
- #
1650
- # Related: StringIO#pos.
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.
1651
560
  #
1652
561
  def eof?: () -> bool
1653
562