rbs 3.7.0 → 3.8.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (169) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +3 -3
  3. data/.github/workflows/ruby.yml +7 -7
  4. data/CHANGELOG.md +68 -0
  5. data/core/array.rbs +1756 -1591
  6. data/core/basic_object.rbs +38 -35
  7. data/core/comparable.rbs +1 -1
  8. data/core/complex.rbs +166 -94
  9. data/core/data.rbs +1 -1
  10. data/core/dir.rbs +1 -17
  11. data/core/encoding.rbs +12 -32
  12. data/core/enumerable.rbs +270 -266
  13. data/core/enumerator.rbs +0 -2
  14. data/core/env.rbs +1 -1
  15. data/core/errno.rbs +33 -16
  16. data/core/errors.rbs +6 -2
  17. data/core/exception.rbs +235 -169
  18. data/core/fiber.rbs +3 -2
  19. data/core/file.rbs +26 -75
  20. data/core/float.rbs +125 -72
  21. data/core/gc.rbs +156 -40
  22. data/core/hash.rbs +122 -143
  23. data/core/integer.rbs +79 -50
  24. data/core/io/buffer.rbs +49 -43
  25. data/core/io.rbs +99 -146
  26. data/core/kernel.rbs +292 -202
  27. data/core/match_data.rbs +76 -2
  28. data/core/math.rbs +0 -36
  29. data/core/module.rbs +28 -23
  30. data/core/nil_class.rbs +2 -2
  31. data/core/numeric.rbs +101 -104
  32. data/core/object.rbs +0 -4
  33. data/core/object_space/weak_key_map.rbs +3 -4
  34. data/core/object_space.rbs +3 -3
  35. data/core/proc.rbs +80 -12
  36. data/core/process.rbs +109 -57
  37. data/core/ractor.rbs +54 -4
  38. data/core/range.rbs +114 -87
  39. data/core/rational.rbs +0 -2
  40. data/core/rbs/unnamed/argf.rbs +234 -33
  41. data/core/rbs/unnamed/env_class.rbs +35 -53
  42. data/core/rbs/unnamed/random.rbs +1 -2
  43. data/core/regexp.rbs +6 -54
  44. data/core/ruby_vm.rbs +88 -9
  45. data/core/rubygems/config_file.rbs +3 -0
  46. data/core/rubygems/errors.rbs +3 -6
  47. data/core/rubygems/platform.rbs +0 -9
  48. data/core/rubygems/rubygems.rbs +3 -6
  49. data/core/rubygems/version.rbs +6 -6
  50. data/core/set.rbs +3 -15
  51. data/core/string.rbs +256 -260
  52. data/core/struct.rbs +6 -18
  53. data/core/symbol.rbs +14 -21
  54. data/core/thread.rbs +32 -35
  55. data/core/time.rbs +131 -50
  56. data/core/trace_point.rbs +124 -113
  57. data/core/true_class.rbs +0 -1
  58. data/core/warning.rbs +9 -2
  59. data/docs/architecture.md +1 -1
  60. data/docs/syntax.md +1 -1
  61. data/ext/rbs_extension/location.c +29 -19
  62. data/ext/rbs_extension/parser.c +268 -293
  63. data/ext/rbs_extension/parserstate.c +56 -22
  64. data/lib/rbs/annotate/annotations.rb +3 -3
  65. data/lib/rbs/annotate/rdoc_source.rb +2 -2
  66. data/lib/rbs/cli/diff.rb +3 -3
  67. data/lib/rbs/cli/validate.rb +1 -1
  68. data/lib/rbs/cli.rb +13 -13
  69. data/lib/rbs/collection/config.rb +3 -1
  70. data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
  71. data/lib/rbs/environment_loader.rb +1 -1
  72. data/lib/rbs/namespace.rb +1 -0
  73. data/lib/rbs/parser_aux.rb +2 -2
  74. data/lib/rbs/prototype/rb.rb +11 -8
  75. data/lib/rbs/prototype/rbi.rb +9 -5
  76. data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
  77. data/lib/rbs/prototype/runtime.rb +4 -5
  78. data/lib/rbs/type_name.rb +14 -9
  79. data/lib/rbs/types.rb +2 -1
  80. data/lib/rbs/unit_test/type_assertions.rb +2 -2
  81. data/lib/rbs/validator.rb +3 -1
  82. data/lib/rbs/version.rb +1 -1
  83. data/lib/rdoc_plugin/parser.rb +2 -2
  84. data/rbs.gemspec +4 -0
  85. data/sig/ancestor_graph.rbs +4 -4
  86. data/sig/namespace.rbs +2 -3
  87. data/sig/resolver/constant_resolver.rbs +2 -2
  88. data/sig/resolver/context.rbs +1 -1
  89. data/sig/type_alias_regularity.rbs +5 -5
  90. data/sig/typename.rbs +8 -5
  91. data/sig/use_map.rbs +1 -1
  92. data/sig/validator.rbs +2 -2
  93. data/stdlib/base64/0/base64.rbs +0 -9
  94. data/stdlib/benchmark/0/benchmark.rbs +11 -2
  95. data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
  96. data/stdlib/cgi/0/core.rbs +47 -0
  97. data/stdlib/coverage/0/coverage.rbs +0 -3
  98. data/stdlib/csv/0/csv.rbs +18 -58
  99. data/stdlib/date/0/date.rbs +27 -42
  100. data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
  101. data/stdlib/digest/0/digest.rbs +25 -2
  102. data/stdlib/erb/0/erb.rbs +0 -1
  103. data/stdlib/etc/0/etc.rbs +51 -34
  104. data/stdlib/fileutils/0/fileutils.rbs +3 -44
  105. data/stdlib/io-console/0/io-console.rbs +69 -15
  106. data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
  107. data/stdlib/json/0/json.rbs +56 -71
  108. data/stdlib/logger/0/log_device.rbs +1 -1
  109. data/stdlib/logger/0/logger.rbs +3 -18
  110. data/stdlib/net-http/0/net-http.rbs +39 -106
  111. data/stdlib/nkf/0/nkf.rbs +30 -0
  112. data/stdlib/objspace/0/objspace.rbs +1 -2
  113. data/stdlib/observable/0/observable.rbs +1 -1
  114. data/stdlib/open-uri/0/open-uri.rbs +52 -0
  115. data/stdlib/open3/0/open3.rbs +0 -8
  116. data/stdlib/openssl/0/openssl.rbs +136 -69
  117. data/stdlib/optparse/0/optparse.rbs +58 -18
  118. data/stdlib/pathname/0/pathname.rbs +2 -8
  119. data/stdlib/pp/0/pp.rbs +3 -1
  120. data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
  121. data/stdlib/pstore/0/pstore.rbs +0 -6
  122. data/stdlib/psych/0/psych.rbs +15 -4
  123. data/stdlib/pty/0/pty.rbs +46 -4
  124. data/stdlib/rdoc/0/code_object.rbs +0 -4
  125. data/stdlib/rdoc/0/markup.rbs +10 -12
  126. data/stdlib/rdoc/0/rdoc.rbs +13 -8
  127. data/stdlib/resolv/0/resolv.rbs +13 -4
  128. data/stdlib/ripper/0/ripper.rbs +0 -2
  129. data/stdlib/securerandom/0/securerandom.rbs +7 -2
  130. data/stdlib/shellwords/0/shellwords.rbs +11 -12
  131. data/stdlib/singleton/0/singleton.rbs +0 -1
  132. data/stdlib/socket/0/addrinfo.rbs +0 -1
  133. data/stdlib/socket/0/basic_socket.rbs +0 -5
  134. data/stdlib/socket/0/socket.rbs +32 -27
  135. data/stdlib/socket/0/tcp_server.rbs +0 -3
  136. data/stdlib/socket/0/tcp_socket.rbs +36 -3
  137. data/stdlib/socket/0/udp_socket.rbs +0 -1
  138. data/stdlib/socket/0/unix_server.rbs +0 -3
  139. data/stdlib/strscan/0/string_scanner.rbs +1265 -422
  140. data/stdlib/tempfile/0/tempfile.rbs +135 -28
  141. data/stdlib/time/0/time.rbs +48 -35
  142. data/stdlib/timeout/0/timeout.rbs +11 -8
  143. data/stdlib/tmpdir/0/tmpdir.rbs +10 -3
  144. data/stdlib/tsort/0/tsort.rbs +0 -4
  145. data/stdlib/uri/0/common.rbs +11 -30
  146. data/stdlib/uri/0/ftp.rbs +1 -1
  147. data/stdlib/uri/0/generic.rbs +22 -18
  148. data/stdlib/uri/0/http.rbs +2 -2
  149. data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
  150. data/stdlib/zlib/0/buf_error.rbs +1 -70
  151. data/stdlib/zlib/0/data_error.rbs +1 -70
  152. data/stdlib/zlib/0/deflate.rbs +8 -72
  153. data/stdlib/zlib/0/error.rbs +1 -70
  154. data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
  155. data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
  156. data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
  157. data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
  158. data/stdlib/zlib/0/gzip_file.rbs +1 -71
  159. data/stdlib/zlib/0/gzip_reader.rbs +3 -74
  160. data/stdlib/zlib/0/gzip_writer.rbs +1 -70
  161. data/stdlib/zlib/0/inflate.rbs +4 -71
  162. data/stdlib/zlib/0/mem_error.rbs +1 -70
  163. data/stdlib/zlib/0/need_dict.rbs +1 -70
  164. data/stdlib/zlib/0/stream_end.rbs +1 -70
  165. data/stdlib/zlib/0/stream_error.rbs +1 -70
  166. data/stdlib/zlib/0/version_error.rbs +1 -70
  167. data/stdlib/zlib/0/zlib.rbs +0 -2
  168. data/stdlib/zlib/0/zstream.rbs +4 -72
  169. metadata +3 -6
data/core/string.rbs CHANGED
@@ -1,99 +1,93 @@
1
1
  # <!-- rdoc-file=string.rb -->
2
- # A String object has an arbitrary sequence of bytes, typically representing
3
- # text or binary data. A String object may be created using String::new or as
2
+ # A `String` object has an arbitrary sequence of bytes, typically representing
3
+ # text or binary data. A `String` object may be created using String::new or as
4
4
  # literals.
5
5
  #
6
6
  # String objects differ from Symbol objects in that Symbol objects are designed
7
7
  # to be used as identifiers, instead of text or data.
8
8
  #
9
- # You can create a String object explicitly with:
9
+ # You can create a `String` object explicitly with:
10
10
  #
11
11
  # * A [string literal](rdoc-ref:syntax/literals.rdoc@String+Literals).
12
12
  # * A [heredoc literal](rdoc-ref:syntax/literals.rdoc@Here+Document+Literals).
13
13
  #
14
- #
15
14
  # You can convert certain objects to Strings with:
16
15
  #
17
16
  # * Method #String.
18
17
  #
19
- #
20
- # Some String methods modify `self`. Typically, a method whose name ends with
21
- # `!` modifies `self` and returns `self`; often a similarly named method
18
+ # Some `String` methods modify `self`. Typically, a method whose name ends with
19
+ # `!` modifies `self` and returns `self`; often, a similarly named method
22
20
  # (without the `!`) returns a new string.
23
21
  #
24
- # In general, if there exist both bang and non-bang version of method, the bang!
25
- # mutates and the non-bang! does not. However, a method without a bang can also
26
- # mutate, such as String#replace.
22
+ # In general, if both bang and non-bang versions of a method exist, the bang
23
+ # method mutates and the non-bang method does not. However, a method without a
24
+ # bang can also mutate, such as String#replace.
27
25
  #
28
26
  # ## Substitution Methods
29
27
  #
30
28
  # These methods perform substitutions:
31
29
  #
32
30
  # * String#sub: One substitution (or none); returns a new string.
33
- # * String#sub!: One substitution (or none); returns `self`.
31
+ # * String#sub!: One substitution (or none); returns `self` if any changes,
32
+ # `nil` otherwise.
34
33
  # * String#gsub: Zero or more substitutions; returns a new string.
35
- # * String#gsub!: Zero or more substitutions; returns `self`.
36
- #
34
+ # * String#gsub!: Zero or more substitutions; returns `self` if any changes,
35
+ # `nil` otherwise.
37
36
  #
38
37
  # Each of these methods takes:
39
38
  #
40
- # * A first argument, `pattern` (string or regexp), that specifies the
39
+ # * A first argument, `pattern` (String or Regexp), that specifies the
41
40
  # substring(s) to be replaced.
42
41
  #
43
- # * Either of these:
42
+ # * Either of the following:
44
43
  #
45
- # * A second argument, `replacement` (string or hash), that determines the
44
+ # * A second argument, `replacement` (String or Hash), that determines the
46
45
  # replacing string.
47
46
  # * A block that will determine the replacing string.
48
47
  #
49
- #
50
- #
51
- # The examples in this section mostly use methods String#sub and String#gsub;
52
- # the principles illustrated apply to all four substitution methods.
48
+ # The examples in this section mostly use the String#sub and String#gsub
49
+ # methods; the principles illustrated apply to all four substitution methods.
53
50
  #
54
51
  # **Argument `pattern`**
55
52
  #
56
53
  # Argument `pattern` is commonly a regular expression:
57
54
  #
58
55
  # s = 'hello'
59
- # s.sub(/[aeiou]/, '*')# => "h*llo"
56
+ # s.sub(/[aeiou]/, '*') # => "h*llo"
60
57
  # s.gsub(/[aeiou]/, '*') # => "h*ll*"
61
- # s.gsub(/[aeiou]/, '')# => "hll"
62
- # s.sub(/ell/, 'al') # => "halo"
63
- # s.gsub(/xyzzy/, '*') # => "hello"
58
+ # s.gsub(/[aeiou]/, '') # => "hll"
59
+ # s.sub(/ell/, 'al') # => "halo"
60
+ # s.gsub(/xyzzy/, '*') # => "hello"
64
61
  # 'THX1138'.gsub(/\d+/, '00') # => "THX00"
65
62
  #
66
63
  # When `pattern` is a string, all its characters are treated as ordinary
67
- # characters (not as regexp special characters):
64
+ # characters (not as Regexp special characters):
68
65
  #
69
66
  # 'THX1138'.gsub('\d+', '00') # => "THX1138"
70
67
  #
71
- # **\String `replacement`**
68
+ # **`String` `replacement`**
72
69
  #
73
- # If `replacement` is a string, that string will determine the replacing string
74
- # that is to be substituted for the matched text.
70
+ # If `replacement` is a string, that string determines the replacing string that
71
+ # is substituted for the matched text.
75
72
  #
76
73
  # Each of the examples above uses a simple string as the replacing string.
77
74
  #
78
- # String `replacement` may contain back-references to the pattern's captures:
75
+ # `String` `replacement` may contain back-references to the pattern's captures:
79
76
  #
80
- # * `\n` (*n* a non-negative integer) refers to `$n`.
77
+ # * `\n` (*n* is a non-negative integer) refers to `$n`.
81
78
  # * `\k<name>` refers to the named capture `name`.
82
79
  #
83
- #
84
80
  # See Regexp for details.
85
81
  #
86
82
  # Note that within the string `replacement`, a character combination such as
87
- # `$&` is treated as ordinary text, and not as a special match variable.
88
- # However, you may refer to some special match variables using these
89
- # combinations:
83
+ # `$&` is treated as ordinary text, not as a special match variable. However,
84
+ # you may refer to some special match variables using these combinations:
90
85
  #
91
86
  # * `\&` and `\0` correspond to `$&`, which contains the complete matched
92
87
  # text.
93
- # * `\'` corresponds to `$'`, which contains string after match.
94
- # * `\`` corresponds to `$``, which contains string before match.
95
- # * `\+` corresponds to `$+`, which contains last capture group.
96
- #
88
+ # * `\'` corresponds to `$'`, which contains the string after the match.
89
+ # * `\`` corresponds to `$``, which contains the string before the match.
90
+ # * `\+` corresponds to `$+`, which contains the last capture group.
97
91
  #
98
92
  # See Regexp for details.
99
93
  #
@@ -108,16 +102,16 @@
108
102
  # double-quoted string literal, you need to write `"..\\\\&.."`.
109
103
  #
110
104
  # If you want to write a non-back-reference string `\&` in `replacement`, you
111
- # need first to escape the backslash to prevent this method from interpreting it
105
+ # need to first escape the backslash to prevent this method from interpreting it
112
106
  # as a back-reference, and then you need to escape the backslashes again to
113
107
  # prevent a string literal from consuming them: `"..\\\\\\\\&.."`.
114
108
  #
115
- # You may want to use the block form to avoid a lot of backslashes.
109
+ # You may want to use the block form to avoid excessive backslashes.
116
110
  #
117
111
  # **\Hash `replacement`**
118
112
  #
119
- # If argument `replacement` is a hash, and `pattern` matches one of its keys,
120
- # the replacing string is the value for that key:
113
+ # If the argument `replacement` is a hash, and `pattern` matches one of its
114
+ # keys, the replacing string is the value for that key:
121
115
  #
122
116
  # h = {'foo' => 'bar', 'baz' => 'bat'}
123
117
  # 'food'.sub('foo', h) # => "bard"
@@ -132,15 +126,15 @@
132
126
  # In the block form, the current match string is passed to the block; the
133
127
  # block's return value becomes the replacing string:
134
128
  #
135
- # s = '@'
136
- # '1234'.gsub(/\d/) {|match| s.succ! } # => "ABCD"
129
+ # s = '@'
130
+ # '1234'.gsub(/\d/) { |match| s.succ! } # => "ABCD"
137
131
  #
138
132
  # Special match variables such as `$1`, `$2`, `$``, `$&`, and `$'` are set
139
133
  # appropriately.
140
134
  #
141
135
  # ## Whitespace in Strings
142
136
  #
143
- # In class String, *whitespace* is defined as a contiguous sequence of
137
+ # In the class `String`, *whitespace* is defined as a contiguous sequence of
144
138
  # characters consisting of any mixture of the following:
145
139
  #
146
140
  # * NL (null): `"\x00"`, `"\u0000"`.
@@ -151,55 +145,51 @@
151
145
  # * CR (carriage return): `"\x0d"`, `"\r"`.
152
146
  # * SP (space): `"\x20"`, `" "`.
153
147
  #
148
+ # Whitespace is relevant for the following methods:
154
149
  #
155
- # Whitespace is relevant for these methods:
156
- #
157
- # * #lstrip, #lstrip!: strip leading whitespace.
158
- # * #rstrip, #rstrip!: strip trailing whitespace.
159
- # * #strip, #strip!: strip leading and trailing whitespace.
160
- #
150
+ # * #lstrip, #lstrip!: Strip leading whitespace.
151
+ # * #rstrip, #rstrip!: Strip trailing whitespace.
152
+ # * #strip, #strip!: Strip leading and trailing whitespace.
161
153
  #
162
- # ## String Slices
154
+ # ## `String` Slices
163
155
  #
164
- # A *slice* of a string is a substring that is selected by certain criteria.
156
+ # A *slice* of a string is a substring selected by certain criteria.
165
157
  #
166
- # These instance methods make use of slicing:
167
- #
168
- # * String#[] (also aliased as String#slice) returns a slice copied from
169
- # `self`.
170
- # * String#[]= returns a copy of `self` with a slice replaced.
171
- # * String#slice! returns `self` with a slice removed.
158
+ # These instance methods utilize slicing:
172
159
  #
160
+ # * String#[] (aliased as String#slice): Returns a slice copied from `self`.
161
+ # * String#[]=: Mutates `self` with the slice replaced.
162
+ # * String#slice!: Mutates `self` with the slice removed and returns the
163
+ # removed slice.
173
164
  #
174
165
  # Each of the above methods takes arguments that determine the slice to be
175
166
  # copied or replaced.
176
167
  #
177
- # The arguments have several forms. For string `string`, the forms are:
178
- #
179
- # * `string[index]`.
180
- # * `string[start, length]`.
181
- # * `string[range]`.
182
- # * `string[regexp, capture = 0]`.
183
- # * `string[substring]`.
168
+ # The arguments have several forms. For a string `string`, the forms are:
184
169
  #
170
+ # * `string[index]`
171
+ # * `string[start, length]`
172
+ # * `string[range]`
173
+ # * `string[regexp, capture = 0]`
174
+ # * `string[substring]`
185
175
  #
186
176
  # **`string[index]`**
187
177
  #
188
- # When non-negative integer argument `index` is given, the slice is the
178
+ # When a non-negative integer argument `index` is given, the slice is the
189
179
  # 1-character substring found in `self` at character offset `index`:
190
180
  #
191
- # 'bar'[0] # => "b"
192
- # 'bar'[2] # => "r"
193
- # 'bar'[20] # => nil
194
- # 'тест'[2] # => "с"
195
- # 'こんにちは'[4] # => "は"
181
+ # 'bar'[0] # => "b"
182
+ # 'bar'[2] # => "r"
183
+ # 'bar'[20] # => nil
184
+ # 'тест'[2] # => "с"
185
+ # 'こんにちは'[4] # => "は"
196
186
  #
197
- # When negative integer `index` is given, the slice begins at the offset given
187
+ # When a negative integer `index` is given, the slice begins at the offset given
198
188
  # by counting backward from the end of `self`:
199
189
  #
200
- # 'bar'[-3] # => "b"
201
- # 'bar'[-1] # => "r"
202
- # 'bar'[-20] # => nil
190
+ # 'bar'[-3] # => "b"
191
+ # 'bar'[-1] # => "r"
192
+ # 'bar'[-20] # => nil
203
193
  #
204
194
  # **`string[start, length]`**
205
195
  #
@@ -207,105 +197,104 @@
207
197
  # begins at character offset `start`, if it exists, and continues for `length`
208
198
  # characters, if available:
209
199
  #
210
- # 'foo'[0, 2] # => "fo"
211
- # 'тест'[1, 2] # => "ес"
212
- # 'こんにちは'[2, 2] # => "にち"
200
+ # 'foo'[0, 2] # => "fo"
201
+ # 'тест'[1, 2] # => "ес"
202
+ # 'こんにちは'[2, 2] # => "にち"
213
203
  # # Zero length.
214
- # 'foo'[2, 0] # => ""
204
+ # 'foo'[2, 0] # => ""
215
205
  # # Length not entirely available.
216
- # 'foo'[1, 200] # => "oo"
206
+ # 'foo'[1, 200] # => "oo"
217
207
  # # Start out of range.
218
208
  # 'foo'[4, 2] # => nil
219
209
  #
220
- # Special case: if `start` is equal to the length of `self`, the slice is a new
221
- # empty string:
210
+ # Special case: if `start` equals the length of `self`, the slice is a new empty
211
+ # string:
222
212
  #
223
- # 'foo'[3, 2] # => ""
224
- # 'foo'[3, 200] # => ""
213
+ # 'foo'[3, 2] # => ""
214
+ # 'foo'[3, 200] # => ""
225
215
  #
226
- # When negative `start` and non-negative `length` are given, the slice beginning
227
- # is determined by counting backward from the end of `self`, and the slice
228
- # continues for `length` characters, if available:
216
+ # When a negative `start` and non-negative `length` are given, the slice begins
217
+ # by counting backward from the end of `self`, and continues for `length`
218
+ # characters, if available:
229
219
  #
230
- # 'foo'[-2, 2] # => "oo"
231
- # 'foo'[-2, 200] # => "oo"
220
+ # 'foo'[-2, 2] # => "oo"
221
+ # 'foo'[-2, 200] # => "oo"
232
222
  # # Start out of range.
233
223
  # 'foo'[-4, 2] # => nil
234
224
  #
235
- # When negative `length` is given, there is no slice:
225
+ # When a negative `length` is given, there is no slice:
236
226
  #
237
- # 'foo'[1, -1] # => nil
238
- # 'foo'[-2, -1] # => nil
227
+ # 'foo'[1, -1] # => nil
228
+ # 'foo'[-2, -1] # => nil
239
229
  #
240
230
  # **`string[range]`**
241
231
  #
242
- # When Range argument `range` is given, creates a substring of `string` using
243
- # the indices in `range`. The slice is then determined as above:
232
+ # When a Range argument `range` is given, it creates a substring of `string`
233
+ # using the indices in `range`. The slice is then determined as above:
244
234
  #
245
- # 'foo'[0..1] # => "fo"
246
- # 'foo'[0, 2] # => "fo"
235
+ # 'foo'[0..1] # => "fo"
236
+ # 'foo'[0, 2] # => "fo"
247
237
  #
248
- # 'foo'[2...2] # => ""
249
- # 'foo'[2, 0] # => ""
238
+ # 'foo'[2...2] # => ""
239
+ # 'foo'[2, 0] # => ""
250
240
  #
251
- # 'foo'[1..200] # => "oo"
252
- # 'foo'[1, 200] # => "oo"
241
+ # 'foo'[1..200] # => "oo"
242
+ # 'foo'[1, 200] # => "oo"
253
243
  #
254
- # 'foo'[4..5] # => nil
255
- # 'foo'[4, 2] # => nil
244
+ # 'foo'[4..5] # => nil
245
+ # 'foo'[4, 2] # => nil
256
246
  #
257
- # 'foo'[-4..-3] # => nil
258
- # 'foo'[-4, 2] # => nil
247
+ # 'foo'[-4..-3] # => nil
248
+ # 'foo'[-4, 2] # => nil
259
249
  #
260
- # 'foo'[3..4] # => ""
261
- # 'foo'[3, 2] # => ""
250
+ # 'foo'[3..4] # => ""
251
+ # 'foo'[3, 2] # => ""
262
252
  #
263
- # 'foo'[-2..-1] # => "oo"
264
- # 'foo'[-2, 2] # => "oo"
253
+ # 'foo'[-2..-1] # => "oo"
254
+ # 'foo'[-2, 2] # => "oo"
265
255
  #
266
- # 'foo'[-2..197] # => "oo"
267
- # 'foo'[-2, 200] # => "oo"
256
+ # 'foo'[-2..197] # => "oo"
257
+ # 'foo'[-2, 200] # => "oo"
268
258
  #
269
259
  # **`string[regexp, capture = 0]`**
270
260
  #
271
261
  # When the Regexp argument `regexp` is given, and the `capture` argument is `0`,
272
262
  # the slice is the first matching substring found in `self`:
273
263
  #
274
- # 'foo'[/o/] # => "o"
275
- # 'foo'[/x/] # => nil
264
+ # 'foo'[/o/] # => "o"
265
+ # 'foo'[/x/] # => nil
276
266
  # s = 'hello there'
277
- # s[/[aeiou](.)\1/] # => "ell"
278
- # s[/[aeiou](.)\1/, 0] # => "ell"
267
+ # s[/[aeiou](.)\1/] # => "ell"
268
+ # s[/[aeiou](.)\1/, 0] # => "ell"
279
269
  #
280
- # If argument `capture` is given and not `0`, it should be either an capture
281
- # group index (integer) or a capture group name (string or symbol); the slice is
282
- # the specified capture (see Regexp@Groups+and+Captures):
270
+ # If the argument `capture` is provided and not `0`, it should be either a
271
+ # capture group index (integer) or a capture group name (String or Symbol); the
272
+ # slice is the specified capture (see Regexp@Groups and Captures):
283
273
  #
284
274
  # s = 'hello there'
285
275
  # s[/[aeiou](.)\1/, 1] # => "l"
286
276
  # s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] # => "l"
287
- # s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e"
277
+ # s[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, :vowel] # => "e"
288
278
  #
289
279
  # If an invalid capture group index is given, there is no slice. If an invalid
290
280
  # capture group name is given, `IndexError` is raised.
291
281
  #
292
282
  # **`string[substring]`**
293
283
  #
294
- # When the single String argument `substring` is given, returns the substring
295
- # from `self` if found, otherwise `nil`:
284
+ # When the single `String` argument `substring` is given, it returns the
285
+ # substring from `self` if found, otherwise `nil`:
296
286
  #
297
287
  # 'foo'['oo'] # => "oo"
298
288
  # 'foo'['xx'] # => nil
299
289
  #
300
290
  # ## What's Here
301
291
  #
302
- # First, what's elsewhere. Class String:
303
- #
304
- # * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
305
- # * Includes [module Comparable](rdoc-ref:Comparable@What-27s+Here).
292
+ # First, what's elsewhere. Class `String`:
306
293
  #
294
+ # * Inherits from the [Object class](rdoc-ref:Object@What-27s+Here).
295
+ # * Includes the [Comparable module](rdoc-ref:Comparable@What-27s+Here).
307
296
  #
308
- # Here, class String provides methods that are useful for:
297
+ # Here, class `String` provides methods that are useful for:
309
298
  #
310
299
  # * [Creating a String](rdoc-ref:String@Methods+for+Creating+a+String)
311
300
  # * [Frozen/Unfrozen
@@ -316,35 +305,31 @@
316
305
  # * [Converting to New
317
306
  # String](rdoc-ref:String@Methods+for+Converting+to+New+String)
318
307
  # * [Converting to
319
- # Non-String](rdoc-ref:String@Methods+for+Converting+to+Non--5CString)
308
+ # Non-String](rdoc-ref:String@Methods+for+Converting+to+Non-String)
320
309
  # * [Iterating](rdoc-ref:String@Methods+for+Iterating)
321
310
  #
322
- #
323
- # ### Methods for Creating a String
311
+ # ### Methods for Creating a `String`
324
312
  #
325
313
  # * ::new: Returns a new string.
326
314
  # * ::try_convert: Returns a new string created from a given object.
327
315
  #
328
- #
329
316
  # ### Methods for a Frozen/Unfrozen String
330
317
  #
331
- # * #+@: Returns a string that is not frozen: `self`, if not frozen;
332
- # `self.dup` otherwise.
333
- # * #-@: Returns a string that is frozen: `self`, if already frozen;
334
- # `self.freeze` otherwise.
335
- # * #freeze: Freezes `self`, if not already frozen; returns `self`.
336
- #
318
+ # * #+@: Returns a string that is not frozen: `self` if not frozen; `self.dup`
319
+ # otherwise.
320
+ # * #-@ (aliased as #dedup): Returns a string that is frozen: `self` if
321
+ # already frozen; `self.freeze` otherwise.
322
+ # * #freeze: Freezes `self` if not already frozen; returns `self`.
337
323
  #
338
324
  # ### Methods for Querying
339
325
  #
340
326
  # *Counts*
341
327
  #
342
- # * #length, #size: Returns the count of characters (not bytes).
328
+ # * #length (aliased as #size): Returns the count of characters (not bytes).
343
329
  # * #empty?: Returns `true` if `self.length` is zero; `false` otherwise.
344
330
  # * #bytesize: Returns the count of bytes.
345
331
  # * #count: Returns the count of substrings matching given strings.
346
332
  #
347
- #
348
333
  # *Substrings*
349
334
  #
350
335
  # * #=~: Returns the index of the first substring that matches a given Regexp
@@ -364,7 +349,6 @@
364
349
  # * #end_with?: Returns `true` if the string ends with any of the given
365
350
  # substrings.
366
351
  #
367
- #
368
352
  # *Encodings*
369
353
  #
370
354
  # * #encoding: Returns the Encoding object that represents the encoding of the
@@ -376,17 +360,15 @@
376
360
  # * #ascii_only?: Returns `true` if the string has only ASCII characters;
377
361
  # `false` otherwise.
378
362
  #
379
- #
380
363
  # *Other*
381
364
  #
382
365
  # * #sum: Returns a basic checksum for the string: the sum of each byte.
383
366
  # * #hash: Returns the integer hash code.
384
367
  #
385
- #
386
368
  # ### Methods for Comparing
387
369
  #
388
- # * #==, #===: Returns `true` if a given other string has the same content as
389
- # `self`.
370
+ # * #== (aliased as #===): Returns `true` if a given other string has the same
371
+ # content as `self`.
390
372
  # * #eql?: Returns `true` if the content is the same as the given other
391
373
  # string.
392
374
  # * #<=>: Returns -1, 0, or 1 as a given other string is smaller than, equal
@@ -396,16 +378,17 @@
396
378
  # * #casecmp?: Returns `true` if the string is equal to a given string after
397
379
  # Unicode case folding; `false` otherwise.
398
380
  #
399
- #
400
- # ### Methods for Modifying a String
381
+ # ### Methods for Modifying a `String`
401
382
  #
402
383
  # Each of these methods modifies `self`.
403
384
  #
404
385
  # *Insertion*
405
386
  #
406
- # * #insert: Returns `self` with a given string inserted at a given offset.
387
+ # * #insert: Returns `self` with a given string inserted at a specified
388
+ # offset.
407
389
  # * #<<: Returns `self` concatenated with a given string or integer.
408
- #
390
+ # * #append_as_bytes: Returns `self` concatenated with strings without
391
+ # performing any encoding validation or conversion.
409
392
  #
410
393
  # *Substitution*
411
394
  #
@@ -413,9 +396,10 @@
413
396
  # given replacement string; returns `self` if any changes, `nil` otherwise.
414
397
  # * #gsub!: Replaces each substring that matches a given pattern with a given
415
398
  # replacement string; returns `self` if any changes, `nil` otherwise.
416
- # * #succ!, #next!: Returns `self` modified to become its own successor.
417
- # * #replace: Returns `self` with its entire content replaced by a given
418
- # string.
399
+ # * #succ! (aliased as #next!): Returns `self` modified to become its own
400
+ # successor.
401
+ # * #initialize_copy (aliased as #replace): Returns `self` with its entire
402
+ # content replaced by a given string.
419
403
  # * #reverse!: Returns `self` with its characters in reverse order.
420
404
  # * #setbyte: Sets the byte at a given integer offset to a given value;
421
405
  # returns the argument.
@@ -425,7 +409,6 @@
425
409
  # characters, removing duplicates from the substrings that were modified;
426
410
  # returns `self` if any changes, `nil` otherwise.
427
411
  #
428
- #
429
412
  # *Casing*
430
413
  #
431
414
  # * #capitalize!: Upcases the initial character and downcases all others;
@@ -437,17 +420,15 @@
437
420
  # * #swapcase!: Upcases each downcase character and downcases each upcase
438
421
  # character; returns `self` if any changes, `nil` otherwise.
439
422
  #
440
- #
441
423
  # *Encoding*
442
424
  #
443
- # * #encode!: Returns `self` with all characters transcoded from one given
444
- # encoding into another.
425
+ # * #encode!: Returns `self` with all characters transcoded from one encoding
426
+ # to another.
445
427
  # * #unicode_normalize!: Unicode-normalizes `self`; returns `self`.
446
428
  # * #scrub!: Replaces each invalid byte with a given character; returns
447
429
  # `self`.
448
430
  # * #force_encoding: Changes the encoding to a given encoding; returns `self`.
449
431
  #
450
- #
451
432
  # *Deletion*
452
433
  #
453
434
  # * #clear: Removes all content, so that `self` is empty; returns `self`.
@@ -462,22 +443,21 @@
462
443
  # `nil` otherwise.
463
444
  # * #strip!: Removes leading and trailing whitespace; returns `self` if any
464
445
  # changes, `nil` otherwise.
465
- # * #chomp!: Removes trailing record separator, if found; returns `self` if
466
- # any changes, `nil` otherwise.
446
+ # * #chomp!: Removes the trailing record separator, if found; returns `self`
447
+ # if any changes, `nil` otherwise.
467
448
  # * #chop!: Removes trailing newline characters if found; otherwise removes
468
449
  # the last character; returns `self` if any changes, `nil` otherwise.
469
450
  #
451
+ # ### Methods for Converting to New `String`
470
452
  #
471
- # ### Methods for Converting to New String
472
- #
473
- # Each of these methods returns a new String based on `self`, often just a
453
+ # Each of these methods returns a new `String` based on `self`, often just a
474
454
  # modified copy of `self`.
475
455
  #
476
456
  # *Extension*
477
457
  #
478
- # * #*: Returns the concatenation of multiple copies of `self`,
458
+ # * #*: Returns the concatenation of multiple copies of `self`.
479
459
  # * #+: Returns the concatenation of `self` and a given other string.
480
- # * #center: Returns a copy of `self` centered between pad substring.
460
+ # * #center: Returns a copy of `self` centered between pad substrings.
481
461
  # * #concat: Returns the concatenation of `self` with given other strings.
482
462
  # * #prepend: Returns the concatenation of a given other string with `self`.
483
463
  # * #ljust: Returns a copy of `self` of a given length, right-padded with a
@@ -485,7 +465,6 @@
485
465
  # * #rjust: Returns a copy of `self` of a given length, left-padded with a
486
466
  # given other string.
487
467
  #
488
- #
489
468
  # *Encoding*
490
469
  #
491
470
  # * #b: Returns a copy of `self` with ASCII-8BIT encoding.
@@ -494,29 +473,28 @@
494
473
  # * #unicode_normalize: Returns a copy of `self` with each character
495
474
  # Unicode-normalized.
496
475
  # * #encode: Returns a copy of `self` with all characters transcoded from one
497
- # given encoding into another.
498
- #
476
+ # encoding to another.
499
477
  #
500
478
  # *Substitution*
501
479
  #
502
480
  # * #dump: Returns a copy of `self` with all non-printing characters replaced
503
481
  # by xHH notation and all special characters escaped.
504
- # * #undump: Returns a copy of `self` with all `\xNN` notation replace by
505
- # `\uNNNN` notation and all escaped characters unescaped.
482
+ # * #undump: Returns a copy of `self` with all `\xNN` notations replaced by
483
+ # `\uNNNN` notations and all escaped characters unescaped.
506
484
  # * #sub: Returns a copy of `self` with the first substring matching a given
507
- # pattern replaced with a given replacement string;.
485
+ # pattern replaced with a given replacement string.
508
486
  # * #gsub: Returns a copy of `self` with each substring that matches a given
509
487
  # pattern replaced with a given replacement string.
510
- # * #succ, #next: Returns the string that is the successor to `self`.
488
+ # * #succ (aliased as #next): Returns the string that is the successor to
489
+ # `self`.
511
490
  # * #reverse: Returns a copy of `self` with its characters in reverse order.
512
491
  # * #tr: Returns a copy of `self` with specified characters replaced with
513
- # specified replacement characters.
492
+ # specified replacement characters.
514
493
  # * #tr_s: Returns a copy of `self` with specified characters replaced with
515
494
  # specified replacement characters, removing duplicates from the substrings
516
495
  # that were modified.
517
496
  # * #%: Returns the string resulting from formatting a given object into
518
- # `self`
519
- #
497
+ # `self`.
520
498
  #
521
499
  # *Casing*
522
500
  #
@@ -527,10 +505,9 @@
527
505
  # * #swapcase: Returns a copy of `self` with all upcase characters downcased
528
506
  # and all downcase characters upcased.
529
507
  #
530
- #
531
508
  # *Deletion*
532
509
  #
533
- # * #delete: Returns a copy of `self` with characters removed
510
+ # * #delete: Returns a copy of `self` with characters removed.
534
511
  # * #delete_prefix: Returns a copy of `self` with a given prefix removed.
535
512
  # * #delete_suffix: Returns a copy of `self` with a given suffix removed.
536
513
  # * #lstrip: Returns a copy of `self` with leading whitespace removed.
@@ -543,55 +520,50 @@
543
520
  # last character removed.
544
521
  # * #squeeze: Returns a copy of `self` with contiguous duplicate characters
545
522
  # removed.
546
- # * #[], #slice: Returns a substring determined by a given index,
547
- # start/length, or range, or string.
523
+ # * #[] (aliased as #slice): Returns a substring determined by a given index,
524
+ # start/length, range, regexp, or string.
548
525
  # * #byteslice: Returns a substring determined by a given index, start/length,
549
526
  # or range.
550
527
  # * #chr: Returns the first character.
551
528
  #
552
- #
553
529
  # *Duplication*
554
530
  #
555
- # * #to_s, $to_str: If `self` is a subclass of String, returns `self` copied
556
- # into a String; otherwise, returns `self`.
531
+ # * #to_s (aliased as #to_str): If `self` is a subclass of `String`, returns
532
+ # `self` copied into a `String`; otherwise, returns `self`.
557
533
  #
534
+ # ### Methods for Converting to Non-`String`
558
535
  #
559
- # ### Methods for Converting to Non-String
560
- #
561
- # Each of these methods converts the contents of `self` to a non-String.
536
+ # Each of these methods converts the contents of `self` to a non-`String`.
562
537
  #
563
538
  # *Characters, Bytes, and Clusters*
564
539
  #
565
540
  # * #bytes: Returns an array of the bytes in `self`.
566
541
  # * #chars: Returns an array of the characters in `self`.
567
542
  # * #codepoints: Returns an array of the integer ordinals in `self`.
568
- # * #getbyte: Returns an integer byte as determined by a given index.
543
+ # * #getbyte: Returns the integer byte at the given index in `self`.
569
544
  # * #grapheme_clusters: Returns an array of the grapheme clusters in `self`.
570
545
  #
571
- #
572
546
  # *Splitting*
573
547
  #
574
548
  # * #lines: Returns an array of the lines in `self`, as determined by a given
575
549
  # record separator.
576
550
  # * #partition: Returns a 3-element array determined by the first substring
577
- # that matches a given substring or regexp,
551
+ # that matches a given substring or regexp.
578
552
  # * #rpartition: Returns a 3-element array determined by the last substring
579
- # that matches a given substring or regexp,
553
+ # that matches a given substring or regexp.
580
554
  # * #split: Returns an array of substrings determined by a given delimiter --
581
- # regexp or string -- or, if a block given, passes those substrings to the
582
- # block.
583
- #
555
+ # regexp or string -- or, if a block is given, passes those substrings to
556
+ # the block.
584
557
  #
585
558
  # *Matching*
586
559
  #
587
560
  # * #scan: Returns an array of substrings matching a given regexp or string,
588
- # or, if a block given, passes each matching substring to the block.
561
+ # or, if a block is given, passes each matching substring to the block.
589
562
  # * #unpack: Returns an array of substrings extracted from `self` according to
590
563
  # a given format.
591
564
  # * #unpack1: Returns the first substring extracted from `self` according to a
592
565
  # given format.
593
566
  #
594
- #
595
567
  # *Numerics*
596
568
  #
597
569
  # * #hex: Returns the integer value of the leading characters, interpreted as
@@ -604,13 +576,11 @@
604
576
  # * #to_f: Returns the floating-point value of leading characters, interpreted
605
577
  # as a floating-point number.
606
578
  #
607
- #
608
579
  # *Strings and Symbols*
609
580
  #
610
- # * #inspect: Returns copy of `self`, enclosed in double-quotes, with special
611
- # characters escaped.
612
- # * #to_sym, #intern: Returns the symbol corresponding to `self`.
613
- #
581
+ # * #inspect: Returns a copy of `self`, enclosed in double quotes, with
582
+ # special characters escaped.
583
+ # * #intern (aliased as #to_sym): Returns the symbol corresponding to `self`.
614
584
  #
615
585
  # ### Methods for Iterating
616
586
  #
@@ -636,14 +606,14 @@ class String
636
606
  # rdoc-file=string.c
637
607
  # - String.try_convert(object) -> object, new_string, or nil
638
608
  # -->
639
- # If `object` is a String object, returns `object`.
609
+ # If `object` is a `String` object, returns `object`.
640
610
  #
641
611
  # Otherwise if `object` responds to `:to_str`, calls `object.to_str` and returns
642
612
  # the result.
643
613
  #
644
614
  # Returns `nil` if `object` does not respond to `:to_str`.
645
615
  #
646
- # Raises an exception unless `object.to_str` returns a String object.
616
+ # Raises an exception unless `object.to_str` returns a `String` object.
647
617
  #
648
618
  def self.try_convert: (String object) -> String # technically will return `object` unchanged.
649
619
  | (_ToStr object) -> String
@@ -744,7 +714,7 @@ class String
744
714
  # rdoc-file=string.c
745
715
  # - string * integer -> new_string
746
716
  # -->
747
- # Returns a new String containing `integer` copies of `self`:
717
+ # Returns a new `String` containing `integer` copies of `self`:
748
718
  #
749
719
  # "Ho! " * 3 # => "Ho! Ho! Ho! "
750
720
  # "Ho! " * 0 # => ""
@@ -755,7 +725,7 @@ class String
755
725
  # rdoc-file=string.c
756
726
  # - string + other_string -> new_string
757
727
  # -->
758
- # Returns a new String containing `other_string` concatenated to `self`:
728
+ # Returns a new `String` containing `other_string` concatenated to `self`:
759
729
  #
760
730
  # "Hello from " + self.to_s # => "Hello from main"
761
731
  #
@@ -765,7 +735,8 @@ class String
765
735
  # rdoc-file=string.c
766
736
  # - +string -> new_string or self
767
737
  # -->
768
- # Returns `self` if `self` is not frozen.
738
+ # Returns `self` if `self` is not frozen and can be mutated without warning
739
+ # issuance.
769
740
  #
770
741
  # Otherwise returns `self.dup`, which is not frozen.
771
742
  #
@@ -778,7 +749,7 @@ class String
778
749
  # -->
779
750
  # Returns a frozen, possibly pre-existing copy of the string.
780
751
  #
781
- # The returned String will be deduplicated as long as it does not have any
752
+ # The returned `String` will be deduplicated as long as it does not have any
782
753
  # instance variables set on it and is not a String subclass.
783
754
  #
784
755
  # Note that `-string` variant is more convenient for defining constants:
@@ -808,6 +779,22 @@ class String
808
779
  # s = 'foo'
809
780
  # s << 33 # => "foo!"
810
781
  #
782
+ # If that codepoint is not representable in the encoding of *string*, RangeError
783
+ # is raised.
784
+ #
785
+ # s = 'foo'
786
+ # s.encoding # => <Encoding:UTF-8>
787
+ # s << 0x00110000 # 1114112 out of char range (RangeError)
788
+ # s = 'foo'.encode('EUC-JP')
789
+ # s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
790
+ #
791
+ # If the encoding is US-ASCII and the codepoint is 0..0xff, *string* is
792
+ # automatically promoted to ASCII-8BIT.
793
+ #
794
+ # s = 'foo'.encode('US-ASCII')
795
+ # s << 0xff
796
+ # s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
797
+ #
811
798
  # Related: String#concat, which takes multiple arguments.
812
799
  #
813
800
  def <<: (string | Integer str_or_codepoint) -> self
@@ -823,7 +810,6 @@ class String
823
810
  # * 1 if `other_string` is smaller.
824
811
  # * `nil` if the two are incomparable.
825
812
  #
826
- #
827
813
  # Examples:
828
814
  #
829
815
  # 'foo' <=> 'foo' # => 0
@@ -852,7 +838,7 @@ class String
852
838
  # Returns `false` if the two strings' encodings are not compatible:
853
839
  # "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false
854
840
  #
855
- # If `object` is not an instance of String but responds to `to_str`, then the
841
+ # If `object` is not an instance of `String` but responds to `to_str`, then the
856
842
  # two strings are compared using `object.==`.
857
843
  #
858
844
  def ==: (untyped other) -> bool
@@ -869,7 +855,7 @@ class String
869
855
  # Returns `false` if the two strings' encodings are not compatible:
870
856
  # "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false
871
857
  #
872
- # If `object` is not an instance of String but responds to `to_str`, then the
858
+ # If `object` is not an instance of `String` but responds to `to_str`, then the
873
859
  # two strings are compared using `object.==`.
874
860
  #
875
861
  alias === ==
@@ -955,6 +941,30 @@ class String
955
941
  | [T < _ToStr] (Regexp regexp, MatchData::capture backref, T replacement) -> T
956
942
  | [T < _ToStr] (String substring, T replacement) -> T
957
943
 
944
+ # <!--
945
+ # rdoc-file=string.c
946
+ # - append_as_bytes(*objects) -> string
947
+ # -->
948
+ # Concatenates each object in `objects` into `self` without any encoding
949
+ # validation or conversion and returns `self`:
950
+ #
951
+ # s = 'foo'
952
+ # s.append_as_bytes(" \xE2\x82") # => "foo \xE2\x82"
953
+ # s.valid_encoding? # => false
954
+ # s.append_as_bytes("\xAC 12")
955
+ # s.valid_encoding? # => true
956
+ #
957
+ # For each given object `object` that is an Integer, the value is considered a
958
+ # Byte. If the Integer is bigger than one byte, only the lower byte is
959
+ # considered, similar to String#setbyte:
960
+ #
961
+ # s = ""
962
+ # s.append_as_bytes(0, 257) # => "\u0000\u0001"
963
+ #
964
+ # Related: String#<<, String#concat, which do an encoding aware concatenation.
965
+ #
966
+ def append_as_bytes: (String) -> String
967
+
958
968
  # <!--
959
969
  # rdoc-file=string.c
960
970
  # - ascii_only? -> true or false
@@ -1067,13 +1077,12 @@ class String
1067
1077
  # $~ #=> #<MatchData "oo">
1068
1078
  #
1069
1079
  # Integer argument `offset`, if given and non-negative, specifies the maximum
1070
- # starting byte-based position in the
1071
- # string to _end_ the search:
1080
+ # starting byte-based position in the string to *end* the search:
1072
1081
  #
1073
- # 'foo'.byterindex('o', 0) # => nil
1074
- # 'foo'.byterindex('o', 1) # => 1
1075
- # 'foo'.byterindex('o', 2) # => 2
1076
- # 'foo'.byterindex('o', 3) # => 2
1082
+ # 'foo'.byterindex('o', 0) # => nil
1083
+ # 'foo'.byterindex('o', 1) # => 1
1084
+ # 'foo'.byterindex('o', 2) # => 2
1085
+ # 'foo'.byterindex('o', 3) # => 2
1077
1086
  #
1078
1087
  # If `offset` is a negative Integer, the maximum starting position in the string
1079
1088
  # to *end* the search is the sum of the string's length and `offset`:
@@ -1246,7 +1255,6 @@ class String
1246
1255
  # * 1 if `other_string.downcase` is smaller.
1247
1256
  # * `nil` if the two are incomparable.
1248
1257
  #
1249
- #
1250
1258
  # Examples:
1251
1259
  #
1252
1260
  # 'foo'.casecmp('foo') # => 0
@@ -1522,7 +1530,6 @@ class String
1522
1530
  # "foo".crypt("$5$rounds=1000$salt$") # OK, proper usage
1523
1531
  # "foo".crypt("$5$round=1000$salt$") # Typo not detected
1524
1532
  #
1525
- #
1526
1533
  # * Even in the "modular" mode, some hash functions are considered archaic and
1527
1534
  # no longer recommended at all; for instance module `$1$` is officially
1528
1535
  # abandoned by its author: see http://phk.freebsd.dk/sagas/md5crypt_eol/ .
@@ -1536,7 +1543,6 @@ class String
1536
1543
  #
1537
1544
  # "foo".crypt("$5$rounds=1000$salt$") # => "$5fNPQMxC5j6."
1538
1545
  #
1539
- #
1540
1546
  # If for some reason you cannot migrate to other secure contemporary password
1541
1547
  # hashing algorithms, install the string-crypt gem and `require 'string/crypt'`
1542
1548
  # to continue using it.
@@ -1546,7 +1552,7 @@ class String
1546
1552
  # <!-- rdoc-file=string.c -->
1547
1553
  # Returns a frozen, possibly pre-existing copy of the string.
1548
1554
  #
1549
- # The returned String will be deduplicated as long as it does not have any
1555
+ # The returned `String` will be deduplicated as long as it does not have any
1550
1556
  # instance variables set on it and is not a String subclass.
1551
1557
  #
1552
1558
  # Note that `-string` variant is more convenient for defining constants:
@@ -1894,7 +1900,6 @@ class String
1894
1900
  # t = s.encode # => "Ruby™"
1895
1901
  # t.encoding # => #<Encoding:UTF-8>
1896
1902
  #
1897
- #
1898
1903
  # With only argument `dst_encoding` given, uses that encoding:
1899
1904
  #
1900
1905
  # s = "Ruby\x99".force_encoding('Windows-1252')
@@ -2135,7 +2140,7 @@ class String
2135
2140
 
2136
2141
  # <!--
2137
2142
  # rdoc-file=string.c
2138
- # - include? other_string -> true or false
2143
+ # - include?(other_string) -> true or false
2139
2144
  # -->
2140
2145
  # Returns `true` if `self` contains `other_string`, `false` otherwise:
2141
2146
  #
@@ -2227,7 +2232,7 @@ class String
2227
2232
  # - str.intern -> symbol
2228
2233
  # - str.to_sym -> symbol
2229
2234
  # -->
2230
- # Returns the Symbol corresponding to *str*, creating the symbol if it did not
2235
+ # Returns the `Symbol` corresponding to *str*, creating the symbol if it did not
2231
2236
  # previously exist. See Symbol#id2name.
2232
2237
  #
2233
2238
  # "Koala".intern #=> :Koala
@@ -2339,7 +2344,6 @@ class String
2339
2344
  # (see Regexp#match):
2340
2345
  # matchdata = <tt>regexp.match(self)
2341
2346
  #
2342
- #
2343
2347
  # With no block given, returns the computed `matchdata`:
2344
2348
  #
2345
2349
  # 'foo'.match('f') # => #<MatchData "f">
@@ -2434,7 +2438,7 @@ class String
2434
2438
  # s = '99zz99zz'
2435
2439
  # s.succ # => "100aa00aa"
2436
2440
  #
2437
- # The successor to an empty String is a new empty String:
2441
+ # The successor to an empty `String` is a new empty `String`:
2438
2442
  #
2439
2443
  # ''.succ # => ""
2440
2444
  #
@@ -2488,7 +2492,6 @@ class String
2488
2492
  # * `string_or_regexp` itself, if it is a Regexp.
2489
2493
  # * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
2490
2494
  #
2491
- #
2492
2495
  # If the pattern is matched, returns pre-match, first-match, post-match:
2493
2496
  #
2494
2497
  # 'hello'.partition('l') # => ["he", "l", "lo"]
@@ -2590,13 +2593,12 @@ class String
2590
2593
  # $~ #=> #<MatchData "oo">
2591
2594
  #
2592
2595
  # Integer argument `offset`, if given and non-negative, specifies the maximum
2593
- # starting position in the
2594
- # string to _end_ the search:
2596
+ # starting position in the string to *end* the search:
2595
2597
  #
2596
- # 'foo'.rindex('o', 0) # => nil
2597
- # 'foo'.rindex('o', 1) # => 1
2598
- # 'foo'.rindex('o', 2) # => 2
2599
- # 'foo'.rindex('o', 3) # => 2
2598
+ # 'foo'.rindex('o', 0) # => nil
2599
+ # 'foo'.rindex('o', 1) # => 1
2600
+ # 'foo'.rindex('o', 2) # => 2
2601
+ # 'foo'.rindex('o', 3) # => 2
2600
2602
  #
2601
2603
  # If `offset` is a negative Integer, the maximum starting position in the string
2602
2604
  # to *end* the search is the sum of the string's length and `offset`:
@@ -2647,7 +2649,6 @@ class String
2647
2649
  # * `string_or_regexp` itself, if it is a Regexp.
2648
2650
  # * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
2649
2651
  #
2650
- #
2651
2652
  # If the pattern is matched, returns pre-match, last-match, post-match:
2652
2653
  #
2653
2654
  # 'hello'.rpartition('l') # => ["hel", "l", "o"]
@@ -2704,7 +2705,6 @@ class String
2704
2705
  # * `string_or_regexp` itself, if it is a Regexp.
2705
2706
  # * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
2706
2707
  #
2707
- #
2708
2708
  # Iterates through `self`, generating a collection of matching results:
2709
2709
  #
2710
2710
  # * If the pattern contains no groups, each result is the matched string,
@@ -2712,7 +2712,6 @@ class String
2712
2712
  # * If the pattern contains groups, each result is an array containing one
2713
2713
  # entry per group.
2714
2714
  #
2715
- #
2716
2715
  # With no block given, returns an array of the results:
2717
2716
  #
2718
2717
  # s = 'cruel world'
@@ -2733,8 +2732,8 @@ class String
2733
2732
  # <<cruel>> <<world>>
2734
2733
  # rceu lowlr
2735
2734
  #
2736
- def scan: (Regexp pattern) -> Array[String | Array[String]]
2737
- | (Regexp pattern) { (String | Array[String] matches) -> void } -> self
2735
+ def scan: (Regexp pattern) -> Array[String | Array[String?]]
2736
+ | (Regexp pattern) { (String | Array[String?] matches) -> void } -> self
2738
2737
  | (string pattern) -> Array[String]
2739
2738
  | (string pattern) { (String match) -> void } -> self
2740
2739
 
@@ -2844,8 +2843,8 @@ class String
2844
2843
 
2845
2844
  # <!--
2846
2845
  # rdoc-file=string.c
2847
- # - split(field_sep = $;, limit = nil) -> array
2848
- # - split(field_sep = $;, limit = nil) {|substring| ... } -> self
2846
+ # - split(field_sep = $;, limit = 0) -> array
2847
+ # - split(field_sep = $;, limit = 0) {|substring| ... } -> self
2849
2848
  # -->
2850
2849
  # Returns an array of substrings of `self` that are the result of splitting
2851
2850
  # `self` at each occurrence of the given field separator `field_sep`.
@@ -2855,19 +2854,18 @@ class String
2855
2854
  # * If `$;` is `nil` (its default value), the split occurs just as if
2856
2855
  # `field_sep` were given as a space character (see below).
2857
2856
  #
2858
- # * If `$;` is a string, the split ocurs just as if `field_sep` were given as
2857
+ # * If `$;` is a string, the split occurs just as if `field_sep` were given as
2859
2858
  # that string (see below).
2860
2859
  #
2861
- #
2862
- # When `field_sep` is `' '` and `limit` is `nil`, the split occurs at each
2863
- # sequence of whitespace:
2860
+ # When `field_sep` is `' '` and `limit` is `0` (its default value), the split
2861
+ # occurs at each sequence of whitespace:
2864
2862
  #
2865
2863
  # 'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
2866
2864
  # "abc \n\tdef\t\n ghi".split(' ') # => ["abc", "def", "ghi"]
2867
2865
  # 'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
2868
2866
  # ''.split(' ') => []
2869
2867
  #
2870
- # When `field_sep` is a string different from `' '` and `limit` is `nil`, the
2868
+ # When `field_sep` is a string different from `' '` and `limit` is `0`, the
2871
2869
  # split occurs at each occurrence of `field_sep`; trailing empty substrings are
2872
2870
  # not returned:
2873
2871
  #
@@ -2879,7 +2877,7 @@ class String
2879
2877
  # 'тест'.split('т') => ["", "ес"]
2880
2878
  # 'こんにちは'.split('に') => ["こん", "ちは"]
2881
2879
  #
2882
- # When `field_sep` is a Regexp and `limit` is `nil`, the split occurs at each
2880
+ # When `field_sep` is a Regexp and `limit` is `0`, the split occurs at each
2883
2881
  # occurrence of a match; trailing empty substrings are not returned:
2884
2882
  #
2885
2883
  # 'abracadabra'.split(/ab/) # => ["", "racad", "ra"]
@@ -2892,11 +2890,9 @@ class String
2892
2890
  #
2893
2891
  # '1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
2894
2892
  #
2895
- # As seen above, if `limit` is `nil`, trailing empty substrings are not
2896
- # returned; the same is true if `limit` is zero:
2893
+ # As seen above, if `limit` is `0`, trailing empty substrings are not returned:
2897
2894
  #
2898
2895
  # 'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
2899
- # 'aaabcdaaa'.split('a', 0) # => ["", "", "", "bcd"]
2900
2896
  #
2901
2897
  # If `limit` is positive integer `n`, no more than `n - 1-` splits occur, so
2902
2898
  # that at most `n` substrings are returned, and trailing empty substrings are
@@ -2911,7 +2907,7 @@ class String
2911
2907
  # Note that if `field_sep` is a Regexp containing groups, their matches are in
2912
2908
  # the returned array, but do not count toward the limit.
2913
2909
  #
2914
- # If `limit` is negative, it behaves the same as if `limit` was `nil`, meaning
2910
+ # If `limit` is negative, it behaves the same as if `limit` was zero, meaning
2915
2911
  # that there is no limit, and trailing empty substrings are included:
2916
2912
  #
2917
2913
  # 'aaabcdaaa'.split('a', -1) # => ["", "", "", "bcd", "", "", ""]
@@ -2970,7 +2966,6 @@ class String
2970
2966
  # * `string_or_regexp` itself, if it is a Regexp.
2971
2967
  # * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
2972
2968
  #
2973
- #
2974
2969
  # Returns `true` if any pattern matches the beginning, `false` otherwise:
2975
2970
  #
2976
2971
  # 'hello'.start_with?('hell') # => true
@@ -3031,8 +3026,8 @@ class String
3031
3026
  # - sub!(pattern, replacement) -> self or nil
3032
3027
  # - sub!(pattern) {|match| ... } -> self or nil
3033
3028
  # -->
3034
- # Returns `self` with only the first occurrence (not all occurrences) of the
3035
- # given `pattern` replaced.
3029
+ # Replaces the first occurrence (not all occurrences) of the given `pattern` on
3030
+ # `self`; returns `self` if a replacement occurred, `nil` otherwise.
3036
3031
  #
3037
3032
  # See [Substitution Methods](rdoc-ref:String@Substitution+Methods).
3038
3033
  #
@@ -3092,7 +3087,7 @@ class String
3092
3087
  # s = '99zz99zz'
3093
3088
  # s.succ # => "100aa00aa"
3094
3089
  #
3095
- # The successor to an empty String is a new empty String:
3090
+ # The successor to an empty `String` is a new empty `String`:
3096
3091
  #
3097
3092
  # ''.succ # => ""
3098
3093
  #
@@ -3278,19 +3273,19 @@ class String
3278
3273
  # rdoc-file=string.c
3279
3274
  # - to_s -> self or string
3280
3275
  # -->
3281
- # Returns `self` if `self` is a String, or `self` converted to a String if
3282
- # `self` is a subclass of String.
3276
+ # Returns `self` if `self` is a `String`, or `self` converted to a `String` if
3277
+ # `self` is a subclass of `String`.
3283
3278
  #
3284
3279
  def to_s: () -> String
3285
3280
 
3286
3281
  # <!-- rdoc-file=string.c -->
3287
- # Returns `self` if `self` is a String, or `self` converted to a String if
3288
- # `self` is a subclass of String.
3282
+ # Returns `self` if `self` is a `String`, or `self` converted to a `String` if
3283
+ # `self` is a subclass of `String`.
3289
3284
  #
3290
3285
  alias to_str to_s
3291
3286
 
3292
3287
  # <!-- rdoc-file=string.c -->
3293
- # Returns the Symbol corresponding to *str*, creating the symbol if it did not
3288
+ # Returns the `Symbol` corresponding to *str*, creating the symbol if it did not
3294
3289
  # previously exist. See Symbol#id2name.
3295
3290
  #
3296
3291
  # "Koala".intern #=> :Koala
@@ -3320,7 +3315,6 @@ class String
3320
3315
  # translated to the second character in `replacements`.
3321
3316
  # * And so on.
3322
3317
  #
3323
- #
3324
3318
  # Example:
3325
3319
  #
3326
3320
  # 'hello'.tr('el', 'ip') #=> "hippo"
@@ -3411,7 +3405,6 @@ class String
3411
3405
  # * `:nfkc`: Compatibility decomposition, followed by canonical composition.
3412
3406
  # * `:nfkd`: Compatibility decomposition.
3413
3407
  #
3414
- #
3415
3408
  # The encoding of `self` must be one of:
3416
3409
  #
3417
3410
  # * Encoding::UTF_8
@@ -3423,7 +3416,6 @@ class String
3423
3416
  # * Encoding::UCS_2BE
3424
3417
  # * Encoding::UCS_4BE
3425
3418
  #
3426
- #
3427
3419
  # Examples:
3428
3420
  #
3429
3421
  # "a\u0300".unicode_normalize # => "a"
@@ -3470,10 +3462,14 @@ class String
3470
3462
 
3471
3463
  # <!--
3472
3464
  # rdoc-file=pack.rb
3473
- # - unpack(template, offset: 0) -> array
3465
+ # - unpack(template, offset: 0, &block) -> array
3474
3466
  # -->
3475
- # Extracts data from `self`, forming objects that become the elements of a new
3476
- # array; returns that array. See [Packed Data](rdoc-ref:packed_data.rdoc).
3467
+ # Extracts data from `self`.
3468
+ #
3469
+ # If `block` is not given, forming objects that become the elements of a new
3470
+ # array, and returns that array. Otherwise, yields each object.
3471
+ #
3472
+ # See [Packed Data](rdoc-ref:packed_data.rdoc).
3477
3473
  #
3478
3474
  def unpack: (string template, ?offset: int) -> Array[Integer | Float | String | nil]
3479
3475
  | (string template, ?offset: int) { (Integer | Float | String | nil value) -> void } -> nil
@@ -3533,7 +3529,7 @@ class String
3533
3529
  # - upto(other_string, exclusive = false) {|string| ... } -> self
3534
3530
  # - upto(other_string, exclusive = false) -> new_enumerator
3535
3531
  # -->
3536
- # With a block given, calls the block with each String value returned by
3532
+ # With a block given, calls the block with each `String` value returned by
3537
3533
  # successive calls to String#succ; the first value is `self`, the next is
3538
3534
  # `self.succ`, and so on; the sequence terminates when value `other_string` is
3539
3535
  # reached; returns `self`: