rbs 3.7.0 → 3.8.0.pre.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +3 -3
- data/.github/workflows/ruby.yml +7 -7
- data/CHANGELOG.md +52 -0
- data/core/array.rbs +1743 -1580
- data/core/basic_object.rbs +38 -35
- data/core/comparable.rbs +1 -1
- data/core/complex.rbs +165 -93
- data/core/data.rbs +1 -1
- data/core/dir.rbs +1 -17
- data/core/encoding.rbs +12 -6
- data/core/enumerable.rbs +270 -266
- data/core/enumerator.rbs +0 -2
- data/core/env.rbs +1 -1
- data/core/errno.rbs +33 -16
- data/core/errors.rbs +2 -2
- data/core/exception.rbs +236 -170
- data/core/fiber.rbs +3 -2
- data/core/file.rbs +32 -74
- data/core/float.rbs +125 -72
- data/core/gc.rbs +138 -40
- data/core/hash.rbs +120 -141
- data/core/integer.rbs +79 -50
- data/core/io/buffer.rbs +49 -43
- data/core/io.rbs +97 -144
- data/core/kernel.rbs +290 -200
- data/core/match_data.rbs +76 -2
- data/core/math.rbs +0 -36
- data/core/module.rbs +28 -23
- data/core/nil_class.rbs +0 -3
- data/core/numeric.rbs +100 -103
- data/core/object.rbs +0 -4
- data/core/object_space/weak_key_map.rbs +3 -4
- data/core/object_space.rbs +3 -3
- data/core/proc.rbs +0 -2
- data/core/process.rbs +109 -57
- data/core/ractor.rbs +37 -4
- data/core/range.rbs +114 -87
- data/core/rational.rbs +0 -2
- data/core/rbs/unnamed/argf.rbs +234 -33
- data/core/rbs/unnamed/env_class.rbs +35 -53
- data/core/rbs/unnamed/random.rbs +1 -2
- data/core/regexp.rbs +4 -52
- data/core/ruby_vm.rbs +88 -9
- data/core/rubygems/config_file.rbs +3 -0
- data/core/rubygems/errors.rbs +0 -5
- data/core/rubygems/platform.rbs +0 -9
- data/core/rubygems/rubygems.rbs +0 -5
- data/core/rubygems/version.rbs +6 -6
- data/core/set.rbs +3 -15
- data/core/string.rbs +130 -136
- data/core/struct.rbs +6 -18
- data/core/symbol.rbs +14 -21
- data/core/thread.rbs +32 -35
- data/core/time.rbs +127 -50
- data/core/trace_point.rbs +16 -0
- data/core/true_class.rbs +0 -1
- data/core/warning.rbs +9 -2
- data/docs/architecture.md +1 -1
- data/docs/syntax.md +1 -1
- data/ext/rbs_extension/location.c +29 -19
- data/ext/rbs_extension/parser.c +267 -292
- data/ext/rbs_extension/parserstate.c +56 -22
- data/lib/rbs/annotate/annotations.rb +3 -3
- data/lib/rbs/annotate/rdoc_source.rb +2 -2
- data/lib/rbs/cli/diff.rb +3 -3
- data/lib/rbs/cli/validate.rb +1 -1
- data/lib/rbs/cli.rb +13 -13
- data/lib/rbs/collection/config.rb +3 -1
- data/lib/rbs/definition_builder/ancestor_builder.rb +3 -3
- data/lib/rbs/environment_loader.rb +1 -1
- data/lib/rbs/namespace.rb +1 -0
- data/lib/rbs/parser_aux.rb +2 -2
- data/lib/rbs/prototype/rb.rb +11 -8
- data/lib/rbs/prototype/rbi.rb +9 -5
- data/lib/rbs/prototype/runtime/value_object_generator.rb +7 -5
- data/lib/rbs/prototype/runtime.rb +4 -5
- data/lib/rbs/type_name.rb +14 -9
- data/lib/rbs/unit_test/type_assertions.rb +2 -2
- data/lib/rbs/validator.rb +3 -1
- data/lib/rbs/version.rb +1 -1
- data/lib/rdoc_plugin/parser.rb +2 -2
- data/rbs.gemspec +4 -0
- data/sig/ancestor_graph.rbs +4 -4
- data/sig/namespace.rbs +2 -3
- data/sig/resolver/constant_resolver.rbs +2 -2
- data/sig/resolver/context.rbs +1 -1
- data/sig/type_alias_regularity.rbs +5 -5
- data/sig/typename.rbs +8 -5
- data/sig/use_map.rbs +1 -1
- data/sig/validator.rbs +2 -2
- data/stdlib/base64/0/base64.rbs +0 -9
- data/stdlib/benchmark/0/benchmark.rbs +11 -2
- data/stdlib/bigdecimal/0/big_decimal.rbs +26 -182
- data/stdlib/cgi/0/core.rbs +47 -0
- data/stdlib/coverage/0/coverage.rbs +0 -3
- data/stdlib/csv/0/csv.rbs +18 -58
- data/stdlib/date/0/date.rbs +4 -19
- data/stdlib/did_you_mean/0/did_you_mean.rbs +0 -5
- data/stdlib/digest/0/digest.rbs +25 -2
- data/stdlib/erb/0/erb.rbs +0 -1
- data/stdlib/etc/0/etc.rbs +51 -34
- data/stdlib/fileutils/0/fileutils.rbs +3 -44
- data/stdlib/io-console/0/io-console.rbs +69 -15
- data/stdlib/ipaddr/0/ipaddr.rbs +8 -4
- data/stdlib/json/0/json.rbs +56 -71
- data/stdlib/logger/0/log_device.rbs +1 -1
- data/stdlib/logger/0/logger.rbs +3 -18
- data/stdlib/net-http/0/net-http.rbs +19 -77
- data/stdlib/nkf/0/nkf.rbs +30 -0
- data/stdlib/objspace/0/objspace.rbs +1 -2
- data/stdlib/observable/0/observable.rbs +1 -1
- data/stdlib/open-uri/0/open-uri.rbs +52 -0
- data/stdlib/open3/0/open3.rbs +0 -8
- data/stdlib/openssl/0/openssl.rbs +136 -69
- data/stdlib/optparse/0/optparse.rbs +58 -18
- data/stdlib/pathname/0/pathname.rbs +2 -8
- data/stdlib/pp/0/pp.rbs +3 -1
- data/stdlib/prettyprint/0/prettyprint.rbs +0 -4
- data/stdlib/pstore/0/pstore.rbs +0 -6
- data/stdlib/psych/0/psych.rbs +15 -4
- data/stdlib/pty/0/pty.rbs +46 -4
- data/stdlib/rdoc/0/code_object.rbs +0 -4
- data/stdlib/rdoc/0/markup.rbs +10 -12
- data/stdlib/rdoc/0/rdoc.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +8 -3
- data/stdlib/ripper/0/ripper.rbs +0 -2
- data/stdlib/securerandom/0/securerandom.rbs +0 -2
- data/stdlib/shellwords/0/shellwords.rbs +11 -12
- data/stdlib/singleton/0/singleton.rbs +0 -1
- data/stdlib/socket/0/addrinfo.rbs +0 -1
- data/stdlib/socket/0/basic_socket.rbs +0 -5
- data/stdlib/socket/0/socket.rbs +49 -25
- data/stdlib/socket/0/tcp_server.rbs +0 -3
- data/stdlib/socket/0/tcp_socket.rbs +58 -3
- data/stdlib/socket/0/udp_socket.rbs +0 -1
- data/stdlib/socket/0/unix_server.rbs +0 -3
- data/stdlib/strscan/0/string_scanner.rbs +1265 -422
- data/stdlib/tempfile/0/tempfile.rbs +135 -28
- data/stdlib/time/0/time.rbs +48 -35
- data/stdlib/timeout/0/timeout.rbs +11 -8
- data/stdlib/tmpdir/0/tmpdir.rbs +8 -1
- data/stdlib/tsort/0/tsort.rbs +0 -4
- data/stdlib/uri/0/common.rbs +11 -30
- data/stdlib/uri/0/ftp.rbs +1 -1
- data/stdlib/uri/0/generic.rbs +22 -18
- data/stdlib/uri/0/http.rbs +2 -2
- data/stdlib/uri/0/rfc2396_parser.rbs +3 -0
- data/stdlib/zlib/0/buf_error.rbs +1 -70
- data/stdlib/zlib/0/data_error.rbs +1 -70
- data/stdlib/zlib/0/deflate.rbs +8 -72
- data/stdlib/zlib/0/error.rbs +1 -70
- data/stdlib/zlib/0/gzip_file/crc_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/length_error.rbs +2 -105
- data/stdlib/zlib/0/gzip_file/no_footer.rbs +2 -105
- data/stdlib/zlib/0/gzip_file.rbs +1 -71
- data/stdlib/zlib/0/gzip_reader.rbs +3 -74
- data/stdlib/zlib/0/gzip_writer.rbs +1 -70
- data/stdlib/zlib/0/inflate.rbs +4 -71
- data/stdlib/zlib/0/mem_error.rbs +1 -70
- data/stdlib/zlib/0/need_dict.rbs +1 -70
- data/stdlib/zlib/0/stream_end.rbs +1 -70
- data/stdlib/zlib/0/stream_error.rbs +1 -70
- data/stdlib/zlib/0/version_error.rbs +1 -70
- data/stdlib/zlib/0/zlib.rbs +0 -2
- data/stdlib/zlib/0/zstream.rbs +4 -72
- metadata +4 -6
data/core/string.rbs
CHANGED
|
@@ -1,23 +1,21 @@
|
|
|
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
|
|
18
|
+
# Some `String` methods modify `self`. Typically, a method whose name ends with
|
|
21
19
|
# `!` modifies `self` and returns `self`; often a similarly named method
|
|
22
20
|
# (without the `!`) returns a new string.
|
|
23
21
|
#
|
|
@@ -30,10 +28,11 @@
|
|
|
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
|
#
|
|
@@ -46,8 +45,6 @@
|
|
|
46
45
|
# replacing string.
|
|
47
46
|
# * A block that will determine the replacing string.
|
|
48
47
|
#
|
|
49
|
-
#
|
|
50
|
-
#
|
|
51
48
|
# The examples in this section mostly use methods String#sub and String#gsub;
|
|
52
49
|
# the principles illustrated apply to all four substitution methods.
|
|
53
50
|
#
|
|
@@ -68,19 +65,18 @@
|
|
|
68
65
|
#
|
|
69
66
|
# 'THX1138'.gsub('\d+', '00') # => "THX1138"
|
|
70
67
|
#
|
|
71
|
-
#
|
|
68
|
+
# **`String` `replacement`**
|
|
72
69
|
#
|
|
73
70
|
# If `replacement` is a string, that string will determine the replacing string
|
|
74
71
|
# that is to be 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
77
|
# * `\n` (*n* 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
|
|
@@ -94,7 +90,6 @@
|
|
|
94
90
|
# * `\`` corresponds to `$``, which contains string before match.
|
|
95
91
|
# * `\+` corresponds to `$+`, which contains last capture group.
|
|
96
92
|
#
|
|
97
|
-
#
|
|
98
93
|
# See Regexp for details.
|
|
99
94
|
#
|
|
100
95
|
# Note that `\\\` is interpreted as an escape, i.e., a single backslash.
|
|
@@ -140,7 +135,7 @@
|
|
|
140
135
|
#
|
|
141
136
|
# ## Whitespace in Strings
|
|
142
137
|
#
|
|
143
|
-
# In class String
|
|
138
|
+
# In class `String`, *whitespace* is defined as a contiguous sequence of
|
|
144
139
|
# characters consisting of any mixture of the following:
|
|
145
140
|
#
|
|
146
141
|
# * NL (null): `"\x00"`, `"\u0000"`.
|
|
@@ -151,25 +146,21 @@
|
|
|
151
146
|
# * CR (carriage return): `"\x0d"`, `"\r"`.
|
|
152
147
|
# * SP (space): `"\x20"`, `" "`.
|
|
153
148
|
#
|
|
154
|
-
#
|
|
155
149
|
# Whitespace is relevant for these methods:
|
|
156
150
|
#
|
|
157
151
|
# * #lstrip, #lstrip!: strip leading whitespace.
|
|
158
152
|
# * #rstrip, #rstrip!: strip trailing whitespace.
|
|
159
153
|
# * #strip, #strip!: strip leading and trailing whitespace.
|
|
160
154
|
#
|
|
161
|
-
#
|
|
162
|
-
# ## String Slices
|
|
155
|
+
# ## `String` Slices
|
|
163
156
|
#
|
|
164
157
|
# A *slice* of a string is a substring that is selected by certain criteria.
|
|
165
158
|
#
|
|
166
159
|
# These instance methods make use of slicing:
|
|
167
160
|
#
|
|
168
|
-
# * String#[] (
|
|
169
|
-
#
|
|
170
|
-
# * String#
|
|
171
|
-
# * String#slice! returns `self` with a slice removed.
|
|
172
|
-
#
|
|
161
|
+
# * String#[] (aliased as String#slice): returns a slice copied from `self`.
|
|
162
|
+
# * String#[]=: returns a copy of `self` with a slice replaced.
|
|
163
|
+
# * String#slice!: returns `self` with a slice removed.
|
|
173
164
|
#
|
|
174
165
|
# Each of the above methods takes arguments that determine the slice to be
|
|
175
166
|
# copied or replaced.
|
|
@@ -182,7 +173,6 @@
|
|
|
182
173
|
# * `string[regexp, capture = 0]`.
|
|
183
174
|
# * `string[substring]`.
|
|
184
175
|
#
|
|
185
|
-
#
|
|
186
176
|
# **`string[index]`**
|
|
187
177
|
#
|
|
188
178
|
# When non-negative integer argument `index` is given, the slice is the
|
|
@@ -291,7 +281,7 @@
|
|
|
291
281
|
#
|
|
292
282
|
# **`string[substring]`**
|
|
293
283
|
#
|
|
294
|
-
# When the single String argument `substring` is given, returns the substring
|
|
284
|
+
# When the single `String` argument `substring` is given, returns the substring
|
|
295
285
|
# from `self` if found, otherwise `nil`:
|
|
296
286
|
#
|
|
297
287
|
# 'foo'['oo'] # => "oo"
|
|
@@ -299,13 +289,12 @@
|
|
|
299
289
|
#
|
|
300
290
|
# ## What's Here
|
|
301
291
|
#
|
|
302
|
-
# First, what's elsewhere. Class String
|
|
292
|
+
# First, what's elsewhere. Class `String`:
|
|
303
293
|
#
|
|
304
294
|
# * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
|
|
305
295
|
# * Includes [module Comparable](rdoc-ref:Comparable@What-27s+Here).
|
|
306
296
|
#
|
|
307
|
-
#
|
|
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
|
|
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
318
|
# * #+@: Returns a string that is not frozen: `self`, if not frozen;
|
|
332
319
|
# `self.dup` otherwise.
|
|
333
|
-
# *
|
|
334
|
-
# `self.freeze` otherwise.
|
|
320
|
+
# * #-@ (aliased as #dedup): Returns a string that is frozen: `self`, if
|
|
321
|
+
# already frozen; `self.freeze` otherwise.
|
|
335
322
|
# * #freeze: Freezes `self`, if not already frozen; returns `self`.
|
|
336
323
|
#
|
|
337
|
-
#
|
|
338
324
|
# ### Methods for Querying
|
|
339
325
|
#
|
|
340
326
|
# *Counts*
|
|
341
327
|
#
|
|
342
|
-
# * #length
|
|
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
|
-
# *
|
|
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,8 +378,7 @@
|
|
|
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
|
#
|
|
@@ -405,7 +386,8 @@
|
|
|
405
386
|
#
|
|
406
387
|
# * #insert: Returns `self` with a given string inserted at a given offset.
|
|
407
388
|
# * #<<: Returns `self` concatenated with a given string or integer.
|
|
408
|
-
#
|
|
389
|
+
# * #append_as_bytes: Returns `self` concatenated with strings without
|
|
390
|
+
# performing any encoding validation or conversion.
|
|
409
391
|
#
|
|
410
392
|
# *Substitution*
|
|
411
393
|
#
|
|
@@ -413,9 +395,10 @@
|
|
|
413
395
|
# given replacement string; returns `self` if any changes, `nil` otherwise.
|
|
414
396
|
# * #gsub!: Replaces each substring that matches a given pattern with a given
|
|
415
397
|
# replacement string; returns `self` if any changes, `nil` otherwise.
|
|
416
|
-
# * #succ
|
|
417
|
-
#
|
|
418
|
-
#
|
|
398
|
+
# * #succ! (aliased as #next!): Returns `self` modified to become its own
|
|
399
|
+
# successor.
|
|
400
|
+
# * #initialize_copy (aliased as #replace): Returns `self` with its entire
|
|
401
|
+
# content replaced by a given string.
|
|
419
402
|
# * #reverse!: Returns `self` with its characters in reverse order.
|
|
420
403
|
# * #setbyte: Sets the byte at a given integer offset to a given value;
|
|
421
404
|
# returns the argument.
|
|
@@ -425,7 +408,6 @@
|
|
|
425
408
|
# characters, removing duplicates from the substrings that were modified;
|
|
426
409
|
# returns `self` if any changes, `nil` otherwise.
|
|
427
410
|
#
|
|
428
|
-
#
|
|
429
411
|
# *Casing*
|
|
430
412
|
#
|
|
431
413
|
# * #capitalize!: Upcases the initial character and downcases all others;
|
|
@@ -437,7 +419,6 @@
|
|
|
437
419
|
# * #swapcase!: Upcases each downcase character and downcases each upcase
|
|
438
420
|
# character; returns `self` if any changes, `nil` otherwise.
|
|
439
421
|
#
|
|
440
|
-
#
|
|
441
422
|
# *Encoding*
|
|
442
423
|
#
|
|
443
424
|
# * #encode!: Returns `self` with all characters transcoded from one given
|
|
@@ -447,7 +428,6 @@
|
|
|
447
428
|
# `self`.
|
|
448
429
|
# * #force_encoding: Changes the encoding to a given encoding; returns `self`.
|
|
449
430
|
#
|
|
450
|
-
#
|
|
451
431
|
# *Deletion*
|
|
452
432
|
#
|
|
453
433
|
# * #clear: Removes all content, so that `self` is empty; returns `self`.
|
|
@@ -467,10 +447,9 @@
|
|
|
467
447
|
# * #chop!: Removes trailing newline characters if found; otherwise removes
|
|
468
448
|
# the last character; returns `self` if any changes, `nil` otherwise.
|
|
469
449
|
#
|
|
450
|
+
# ### Methods for Converting to New `String`
|
|
470
451
|
#
|
|
471
|
-
#
|
|
472
|
-
#
|
|
473
|
-
# Each of these methods returns a new String based on `self`, often just a
|
|
452
|
+
# Each of these methods returns a new `String` based on `self`, often just a
|
|
474
453
|
# modified copy of `self`.
|
|
475
454
|
#
|
|
476
455
|
# *Extension*
|
|
@@ -485,7 +464,6 @@
|
|
|
485
464
|
# * #rjust: Returns a copy of `self` of a given length, left-padded with a
|
|
486
465
|
# given other string.
|
|
487
466
|
#
|
|
488
|
-
#
|
|
489
467
|
# *Encoding*
|
|
490
468
|
#
|
|
491
469
|
# * #b: Returns a copy of `self` with ASCII-8BIT encoding.
|
|
@@ -496,7 +474,6 @@
|
|
|
496
474
|
# * #encode: Returns a copy of `self` with all characters transcoded from one
|
|
497
475
|
# given encoding into another.
|
|
498
476
|
#
|
|
499
|
-
#
|
|
500
477
|
# *Substitution*
|
|
501
478
|
#
|
|
502
479
|
# * #dump: Returns a copy of `self` with all non-printing characters replaced
|
|
@@ -507,7 +484,8 @@
|
|
|
507
484
|
# pattern replaced with a given replacement string;.
|
|
508
485
|
# * #gsub: Returns a copy of `self` with each substring that matches a given
|
|
509
486
|
# pattern replaced with a given replacement string.
|
|
510
|
-
# * #succ
|
|
487
|
+
# * #succ (aliased as #next): Returns the string that is the successor to
|
|
488
|
+
# `self`.
|
|
511
489
|
# * #reverse: Returns a copy of `self` with its characters in reverse order.
|
|
512
490
|
# * #tr: Returns a copy of `self` with specified characters replaced with
|
|
513
491
|
# specified replacement characters.
|
|
@@ -517,7 +495,6 @@
|
|
|
517
495
|
# * #%: Returns the string resulting from formatting a given object into
|
|
518
496
|
# `self`
|
|
519
497
|
#
|
|
520
|
-
#
|
|
521
498
|
# *Casing*
|
|
522
499
|
#
|
|
523
500
|
# * #capitalize: Returns a copy of `self` with the first character upcased and
|
|
@@ -527,7 +504,6 @@
|
|
|
527
504
|
# * #swapcase: Returns a copy of `self` with all upcase characters downcased
|
|
528
505
|
# and all downcase characters upcased.
|
|
529
506
|
#
|
|
530
|
-
#
|
|
531
507
|
# *Deletion*
|
|
532
508
|
#
|
|
533
509
|
# * #delete: Returns a copy of `self` with characters removed
|
|
@@ -543,22 +519,20 @@
|
|
|
543
519
|
# last character removed.
|
|
544
520
|
# * #squeeze: Returns a copy of `self` with contiguous duplicate characters
|
|
545
521
|
# removed.
|
|
546
|
-
# * #[]
|
|
522
|
+
# * #[] (aliased as #slice): Returns a substring determined by a given index,
|
|
547
523
|
# start/length, or range, or string.
|
|
548
524
|
# * #byteslice: Returns a substring determined by a given index, start/length,
|
|
549
525
|
# or range.
|
|
550
526
|
# * #chr: Returns the first character.
|
|
551
527
|
#
|
|
552
|
-
#
|
|
553
528
|
# *Duplication*
|
|
554
529
|
#
|
|
555
|
-
# * #to_s
|
|
556
|
-
# into a String
|
|
530
|
+
# * #to_s (aliased as #to_str): If `self` is a subclass of `String`, returns
|
|
531
|
+
# `self` copied into a `String`; otherwise, returns `self`.
|
|
557
532
|
#
|
|
533
|
+
# ### Methods for Converting to Non-`String`
|
|
558
534
|
#
|
|
559
|
-
#
|
|
560
|
-
#
|
|
561
|
-
# Each of these methods converts the contents of `self` to a non-String.
|
|
535
|
+
# Each of these methods converts the contents of `self` to a non-`String`.
|
|
562
536
|
#
|
|
563
537
|
# *Characters, Bytes, and Clusters*
|
|
564
538
|
#
|
|
@@ -568,7 +542,6 @@
|
|
|
568
542
|
# * #getbyte: Returns an integer byte as determined by a given index.
|
|
569
543
|
# * #grapheme_clusters: Returns an array of the grapheme clusters in `self`.
|
|
570
544
|
#
|
|
571
|
-
#
|
|
572
545
|
# *Splitting*
|
|
573
546
|
#
|
|
574
547
|
# * #lines: Returns an array of the lines in `self`, as determined by a given
|
|
@@ -581,7 +554,6 @@
|
|
|
581
554
|
# regexp or string -- or, if a block given, passes those substrings to the
|
|
582
555
|
# block.
|
|
583
556
|
#
|
|
584
|
-
#
|
|
585
557
|
# *Matching*
|
|
586
558
|
#
|
|
587
559
|
# * #scan: Returns an array of substrings matching a given regexp or string,
|
|
@@ -591,7 +563,6 @@
|
|
|
591
563
|
# * #unpack1: Returns the first substring extracted from `self` according to a
|
|
592
564
|
# given format.
|
|
593
565
|
#
|
|
594
|
-
#
|
|
595
566
|
# *Numerics*
|
|
596
567
|
#
|
|
597
568
|
# * #hex: Returns the integer value of the leading characters, interpreted as
|
|
@@ -604,13 +575,11 @@
|
|
|
604
575
|
# * #to_f: Returns the floating-point value of leading characters, interpreted
|
|
605
576
|
# as a floating-point number.
|
|
606
577
|
#
|
|
607
|
-
#
|
|
608
578
|
# *Strings and Symbols*
|
|
609
579
|
#
|
|
610
580
|
# * #inspect: Returns copy of `self`, enclosed in double-quotes, with special
|
|
611
581
|
# characters escaped.
|
|
612
|
-
# * #
|
|
613
|
-
#
|
|
582
|
+
# * #intern (aliased as #to_sym): Returns the symbol corresponding to `self`.
|
|
614
583
|
#
|
|
615
584
|
# ### Methods for Iterating
|
|
616
585
|
#
|
|
@@ -636,14 +605,14 @@ class String
|
|
|
636
605
|
# rdoc-file=string.c
|
|
637
606
|
# - String.try_convert(object) -> object, new_string, or nil
|
|
638
607
|
# -->
|
|
639
|
-
# If `object` is a String object, returns `object`.
|
|
608
|
+
# If `object` is a `String` object, returns `object`.
|
|
640
609
|
#
|
|
641
610
|
# Otherwise if `object` responds to `:to_str`, calls `object.to_str` and returns
|
|
642
611
|
# the result.
|
|
643
612
|
#
|
|
644
613
|
# Returns `nil` if `object` does not respond to `:to_str`.
|
|
645
614
|
#
|
|
646
|
-
# Raises an exception unless `object.to_str` returns a String object.
|
|
615
|
+
# Raises an exception unless `object.to_str` returns a `String` object.
|
|
647
616
|
#
|
|
648
617
|
def self.try_convert: (String object) -> String # technically will return `object` unchanged.
|
|
649
618
|
| (_ToStr object) -> String
|
|
@@ -744,7 +713,7 @@ class String
|
|
|
744
713
|
# rdoc-file=string.c
|
|
745
714
|
# - string * integer -> new_string
|
|
746
715
|
# -->
|
|
747
|
-
# Returns a new String containing `integer` copies of `self`:
|
|
716
|
+
# Returns a new `String` containing `integer` copies of `self`:
|
|
748
717
|
#
|
|
749
718
|
# "Ho! " * 3 # => "Ho! Ho! Ho! "
|
|
750
719
|
# "Ho! " * 0 # => ""
|
|
@@ -755,7 +724,7 @@ class String
|
|
|
755
724
|
# rdoc-file=string.c
|
|
756
725
|
# - string + other_string -> new_string
|
|
757
726
|
# -->
|
|
758
|
-
# Returns a new String containing `other_string` concatenated to `self`:
|
|
727
|
+
# Returns a new `String` containing `other_string` concatenated to `self`:
|
|
759
728
|
#
|
|
760
729
|
# "Hello from " + self.to_s # => "Hello from main"
|
|
761
730
|
#
|
|
@@ -778,7 +747,7 @@ class String
|
|
|
778
747
|
# -->
|
|
779
748
|
# Returns a frozen, possibly pre-existing copy of the string.
|
|
780
749
|
#
|
|
781
|
-
# The returned String will be deduplicated as long as it does not have any
|
|
750
|
+
# The returned `String` will be deduplicated as long as it does not have any
|
|
782
751
|
# instance variables set on it and is not a String subclass.
|
|
783
752
|
#
|
|
784
753
|
# Note that `-string` variant is more convenient for defining constants:
|
|
@@ -808,6 +777,22 @@ class String
|
|
|
808
777
|
# s = 'foo'
|
|
809
778
|
# s << 33 # => "foo!"
|
|
810
779
|
#
|
|
780
|
+
# If that codepoint is not representable in the encoding of *string*, RangeError
|
|
781
|
+
# is raised.
|
|
782
|
+
#
|
|
783
|
+
# s = 'foo'
|
|
784
|
+
# s.encoding # => <Encoding:UTF-8>
|
|
785
|
+
# s << 0x00110000 # 1114112 out of char range (RangeError)
|
|
786
|
+
# s = 'foo'.encode('EUC-JP')
|
|
787
|
+
# s << 0x00800080 # invalid codepoint 0x800080 in EUC-JP (RangeError)
|
|
788
|
+
#
|
|
789
|
+
# If the encoding is US-ASCII and the codepoint is 0..0xff, *string* is
|
|
790
|
+
# automatically promoted to ASCII-8BIT.
|
|
791
|
+
#
|
|
792
|
+
# s = 'foo'.encode('US-ASCII')
|
|
793
|
+
# s << 0xff
|
|
794
|
+
# s.encoding # => #<Encoding:BINARY (ASCII-8BIT)>
|
|
795
|
+
#
|
|
811
796
|
# Related: String#concat, which takes multiple arguments.
|
|
812
797
|
#
|
|
813
798
|
def <<: (string | Integer str_or_codepoint) -> self
|
|
@@ -823,7 +808,6 @@ class String
|
|
|
823
808
|
# * 1 if `other_string` is smaller.
|
|
824
809
|
# * `nil` if the two are incomparable.
|
|
825
810
|
#
|
|
826
|
-
#
|
|
827
811
|
# Examples:
|
|
828
812
|
#
|
|
829
813
|
# 'foo' <=> 'foo' # => 0
|
|
@@ -852,7 +836,7 @@ class String
|
|
|
852
836
|
# Returns `false` if the two strings' encodings are not compatible:
|
|
853
837
|
# "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false
|
|
854
838
|
#
|
|
855
|
-
# If `object` is not an instance of String but responds to `to_str`, then the
|
|
839
|
+
# If `object` is not an instance of `String` but responds to `to_str`, then the
|
|
856
840
|
# two strings are compared using `object.==`.
|
|
857
841
|
#
|
|
858
842
|
def ==: (untyped other) -> bool
|
|
@@ -869,7 +853,7 @@ class String
|
|
|
869
853
|
# Returns `false` if the two strings' encodings are not compatible:
|
|
870
854
|
# "\u{e4 f6 fc}".encode("ISO-8859-1") == ("\u{c4 d6 dc}") # => false
|
|
871
855
|
#
|
|
872
|
-
# If `object` is not an instance of String but responds to `to_str`, then the
|
|
856
|
+
# If `object` is not an instance of `String` but responds to `to_str`, then the
|
|
873
857
|
# two strings are compared using `object.==`.
|
|
874
858
|
#
|
|
875
859
|
alias === ==
|
|
@@ -955,6 +939,30 @@ class String
|
|
|
955
939
|
| [T < _ToStr] (Regexp regexp, MatchData::capture backref, T replacement) -> T
|
|
956
940
|
| [T < _ToStr] (String substring, T replacement) -> T
|
|
957
941
|
|
|
942
|
+
# <!--
|
|
943
|
+
# rdoc-file=string.c
|
|
944
|
+
# - append_as_bytes(*objects) -> string
|
|
945
|
+
# -->
|
|
946
|
+
# Concatenates each object in `objects` into `self` without any encoding
|
|
947
|
+
# validation or conversion and returns `self`:
|
|
948
|
+
#
|
|
949
|
+
# s = 'foo'
|
|
950
|
+
# s.append_as_bytes(" \xE2\x82") # => "foo \xE2\x82"
|
|
951
|
+
# s.valid_encoding? # => false
|
|
952
|
+
# s.append_as_bytes("\xAC 12")
|
|
953
|
+
# s.valid_encoding? # => true
|
|
954
|
+
#
|
|
955
|
+
# For each given object `object` that is an Integer, the value is considered a
|
|
956
|
+
# Byte. If the Integer is bigger than one byte, only the lower byte is
|
|
957
|
+
# considered, similar to String#setbyte:
|
|
958
|
+
#
|
|
959
|
+
# s = ""
|
|
960
|
+
# s.append_as_bytes(0, 257) # => "\u0000\u0001"
|
|
961
|
+
#
|
|
962
|
+
# Related: String#<<, String#concat, which do an encoding aware concatenation.
|
|
963
|
+
#
|
|
964
|
+
def append_as_bytes: (String) -> String
|
|
965
|
+
|
|
958
966
|
# <!--
|
|
959
967
|
# rdoc-file=string.c
|
|
960
968
|
# - ascii_only? -> true or false
|
|
@@ -1067,13 +1075,12 @@ class String
|
|
|
1067
1075
|
# $~ #=> #<MatchData "oo">
|
|
1068
1076
|
#
|
|
1069
1077
|
# Integer argument `offset`, if given and non-negative, specifies the maximum
|
|
1070
|
-
# starting byte-based position in the
|
|
1071
|
-
# string to _end_ the search:
|
|
1078
|
+
# starting byte-based position in the string to *end* the search:
|
|
1072
1079
|
#
|
|
1073
|
-
#
|
|
1074
|
-
#
|
|
1075
|
-
#
|
|
1076
|
-
#
|
|
1080
|
+
# 'foo'.byterindex('o', 0) # => nil
|
|
1081
|
+
# 'foo'.byterindex('o', 1) # => 1
|
|
1082
|
+
# 'foo'.byterindex('o', 2) # => 2
|
|
1083
|
+
# 'foo'.byterindex('o', 3) # => 2
|
|
1077
1084
|
#
|
|
1078
1085
|
# If `offset` is a negative Integer, the maximum starting position in the string
|
|
1079
1086
|
# to *end* the search is the sum of the string's length and `offset`:
|
|
@@ -1246,7 +1253,6 @@ class String
|
|
|
1246
1253
|
# * 1 if `other_string.downcase` is smaller.
|
|
1247
1254
|
# * `nil` if the two are incomparable.
|
|
1248
1255
|
#
|
|
1249
|
-
#
|
|
1250
1256
|
# Examples:
|
|
1251
1257
|
#
|
|
1252
1258
|
# 'foo'.casecmp('foo') # => 0
|
|
@@ -1522,7 +1528,6 @@ class String
|
|
|
1522
1528
|
# "foo".crypt("$5$rounds=1000$salt$") # OK, proper usage
|
|
1523
1529
|
# "foo".crypt("$5$round=1000$salt$") # Typo not detected
|
|
1524
1530
|
#
|
|
1525
|
-
#
|
|
1526
1531
|
# * Even in the "modular" mode, some hash functions are considered archaic and
|
|
1527
1532
|
# no longer recommended at all; for instance module `$1$` is officially
|
|
1528
1533
|
# abandoned by its author: see http://phk.freebsd.dk/sagas/md5crypt_eol/ .
|
|
@@ -1536,7 +1541,6 @@ class String
|
|
|
1536
1541
|
#
|
|
1537
1542
|
# "foo".crypt("$5$rounds=1000$salt$") # => "$5fNPQMxC5j6."
|
|
1538
1543
|
#
|
|
1539
|
-
#
|
|
1540
1544
|
# If for some reason you cannot migrate to other secure contemporary password
|
|
1541
1545
|
# hashing algorithms, install the string-crypt gem and `require 'string/crypt'`
|
|
1542
1546
|
# to continue using it.
|
|
@@ -1546,7 +1550,7 @@ class String
|
|
|
1546
1550
|
# <!-- rdoc-file=string.c -->
|
|
1547
1551
|
# Returns a frozen, possibly pre-existing copy of the string.
|
|
1548
1552
|
#
|
|
1549
|
-
# The returned String will be deduplicated as long as it does not have any
|
|
1553
|
+
# The returned `String` will be deduplicated as long as it does not have any
|
|
1550
1554
|
# instance variables set on it and is not a String subclass.
|
|
1551
1555
|
#
|
|
1552
1556
|
# Note that `-string` variant is more convenient for defining constants:
|
|
@@ -1894,7 +1898,6 @@ class String
|
|
|
1894
1898
|
# t = s.encode # => "Ruby™"
|
|
1895
1899
|
# t.encoding # => #<Encoding:UTF-8>
|
|
1896
1900
|
#
|
|
1897
|
-
#
|
|
1898
1901
|
# With only argument `dst_encoding` given, uses that encoding:
|
|
1899
1902
|
#
|
|
1900
1903
|
# s = "Ruby\x99".force_encoding('Windows-1252')
|
|
@@ -2135,7 +2138,7 @@ class String
|
|
|
2135
2138
|
|
|
2136
2139
|
# <!--
|
|
2137
2140
|
# rdoc-file=string.c
|
|
2138
|
-
# - include?
|
|
2141
|
+
# - include?(other_string) -> true or false
|
|
2139
2142
|
# -->
|
|
2140
2143
|
# Returns `true` if `self` contains `other_string`, `false` otherwise:
|
|
2141
2144
|
#
|
|
@@ -2227,7 +2230,7 @@ class String
|
|
|
2227
2230
|
# - str.intern -> symbol
|
|
2228
2231
|
# - str.to_sym -> symbol
|
|
2229
2232
|
# -->
|
|
2230
|
-
# Returns the Symbol corresponding to *str*, creating the symbol if it did not
|
|
2233
|
+
# Returns the `Symbol` corresponding to *str*, creating the symbol if it did not
|
|
2231
2234
|
# previously exist. See Symbol#id2name.
|
|
2232
2235
|
#
|
|
2233
2236
|
# "Koala".intern #=> :Koala
|
|
@@ -2339,7 +2342,6 @@ class String
|
|
|
2339
2342
|
# (see Regexp#match):
|
|
2340
2343
|
# matchdata = <tt>regexp.match(self)
|
|
2341
2344
|
#
|
|
2342
|
-
#
|
|
2343
2345
|
# With no block given, returns the computed `matchdata`:
|
|
2344
2346
|
#
|
|
2345
2347
|
# 'foo'.match('f') # => #<MatchData "f">
|
|
@@ -2434,7 +2436,7 @@ class String
|
|
|
2434
2436
|
# s = '99zz99zz'
|
|
2435
2437
|
# s.succ # => "100aa00aa"
|
|
2436
2438
|
#
|
|
2437
|
-
# The successor to an empty String is a new empty String
|
|
2439
|
+
# The successor to an empty `String` is a new empty `String`:
|
|
2438
2440
|
#
|
|
2439
2441
|
# ''.succ # => ""
|
|
2440
2442
|
#
|
|
@@ -2488,7 +2490,6 @@ class String
|
|
|
2488
2490
|
# * `string_or_regexp` itself, if it is a Regexp.
|
|
2489
2491
|
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
|
2490
2492
|
#
|
|
2491
|
-
#
|
|
2492
2493
|
# If the pattern is matched, returns pre-match, first-match, post-match:
|
|
2493
2494
|
#
|
|
2494
2495
|
# 'hello'.partition('l') # => ["he", "l", "lo"]
|
|
@@ -2590,13 +2591,12 @@ class String
|
|
|
2590
2591
|
# $~ #=> #<MatchData "oo">
|
|
2591
2592
|
#
|
|
2592
2593
|
# Integer argument `offset`, if given and non-negative, specifies the maximum
|
|
2593
|
-
# starting position in the
|
|
2594
|
-
# string to _end_ the search:
|
|
2594
|
+
# starting position in the string to *end* the search:
|
|
2595
2595
|
#
|
|
2596
|
-
#
|
|
2597
|
-
#
|
|
2598
|
-
#
|
|
2599
|
-
#
|
|
2596
|
+
# 'foo'.rindex('o', 0) # => nil
|
|
2597
|
+
# 'foo'.rindex('o', 1) # => 1
|
|
2598
|
+
# 'foo'.rindex('o', 2) # => 2
|
|
2599
|
+
# 'foo'.rindex('o', 3) # => 2
|
|
2600
2600
|
#
|
|
2601
2601
|
# If `offset` is a negative Integer, the maximum starting position in the string
|
|
2602
2602
|
# to *end* the search is the sum of the string's length and `offset`:
|
|
@@ -2647,7 +2647,6 @@ class String
|
|
|
2647
2647
|
# * `string_or_regexp` itself, if it is a Regexp.
|
|
2648
2648
|
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
|
2649
2649
|
#
|
|
2650
|
-
#
|
|
2651
2650
|
# If the pattern is matched, returns pre-match, last-match, post-match:
|
|
2652
2651
|
#
|
|
2653
2652
|
# 'hello'.rpartition('l') # => ["hel", "l", "o"]
|
|
@@ -2704,7 +2703,6 @@ class String
|
|
|
2704
2703
|
# * `string_or_regexp` itself, if it is a Regexp.
|
|
2705
2704
|
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
|
2706
2705
|
#
|
|
2707
|
-
#
|
|
2708
2706
|
# Iterates through `self`, generating a collection of matching results:
|
|
2709
2707
|
#
|
|
2710
2708
|
# * If the pattern contains no groups, each result is the matched string,
|
|
@@ -2712,7 +2710,6 @@ class String
|
|
|
2712
2710
|
# * If the pattern contains groups, each result is an array containing one
|
|
2713
2711
|
# entry per group.
|
|
2714
2712
|
#
|
|
2715
|
-
#
|
|
2716
2713
|
# With no block given, returns an array of the results:
|
|
2717
2714
|
#
|
|
2718
2715
|
# s = 'cruel world'
|
|
@@ -2733,8 +2730,8 @@ class String
|
|
|
2733
2730
|
# <<cruel>> <<world>>
|
|
2734
2731
|
# rceu lowlr
|
|
2735
2732
|
#
|
|
2736
|
-
def scan: (Regexp pattern) -> Array[String | Array[String]]
|
|
2737
|
-
| (Regexp pattern) { (String | Array[String] matches) -> void } -> self
|
|
2733
|
+
def scan: (Regexp pattern) -> Array[String | Array[String?]]
|
|
2734
|
+
| (Regexp pattern) { (String | Array[String?] matches) -> void } -> self
|
|
2738
2735
|
| (string pattern) -> Array[String]
|
|
2739
2736
|
| (string pattern) { (String match) -> void } -> self
|
|
2740
2737
|
|
|
@@ -2844,8 +2841,8 @@ class String
|
|
|
2844
2841
|
|
|
2845
2842
|
# <!--
|
|
2846
2843
|
# rdoc-file=string.c
|
|
2847
|
-
# - split(field_sep = $;, limit =
|
|
2848
|
-
# - split(field_sep = $;, limit =
|
|
2844
|
+
# - split(field_sep = $;, limit = 0) -> array
|
|
2845
|
+
# - split(field_sep = $;, limit = 0) {|substring| ... } -> self
|
|
2849
2846
|
# -->
|
|
2850
2847
|
# Returns an array of substrings of `self` that are the result of splitting
|
|
2851
2848
|
# `self` at each occurrence of the given field separator `field_sep`.
|
|
@@ -2855,19 +2852,18 @@ class String
|
|
|
2855
2852
|
# * If `$;` is `nil` (its default value), the split occurs just as if
|
|
2856
2853
|
# `field_sep` were given as a space character (see below).
|
|
2857
2854
|
#
|
|
2858
|
-
# * If `$;` is a string, the split
|
|
2855
|
+
# * If `$;` is a string, the split occurs just as if `field_sep` were given as
|
|
2859
2856
|
# that string (see below).
|
|
2860
2857
|
#
|
|
2861
|
-
#
|
|
2862
|
-
#
|
|
2863
|
-
# sequence of whitespace:
|
|
2858
|
+
# When `field_sep` is `' '` and `limit` is `0` (its default value), the split
|
|
2859
|
+
# occurs at each sequence of whitespace:
|
|
2864
2860
|
#
|
|
2865
2861
|
# 'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
|
|
2866
2862
|
# "abc \n\tdef\t\n ghi".split(' ') # => ["abc", "def", "ghi"]
|
|
2867
2863
|
# 'abc def ghi'.split(' ') => ["abc", "def", "ghi"]
|
|
2868
2864
|
# ''.split(' ') => []
|
|
2869
2865
|
#
|
|
2870
|
-
# When `field_sep` is a string different from `' '` and `limit` is `
|
|
2866
|
+
# When `field_sep` is a string different from `' '` and `limit` is `0`, the
|
|
2871
2867
|
# split occurs at each occurrence of `field_sep`; trailing empty substrings are
|
|
2872
2868
|
# not returned:
|
|
2873
2869
|
#
|
|
@@ -2879,7 +2875,7 @@ class String
|
|
|
2879
2875
|
# 'тест'.split('т') => ["", "ес"]
|
|
2880
2876
|
# 'こんにちは'.split('に') => ["こん", "ちは"]
|
|
2881
2877
|
#
|
|
2882
|
-
# When `field_sep` is a Regexp and `limit` is `
|
|
2878
|
+
# When `field_sep` is a Regexp and `limit` is `0`, the split occurs at each
|
|
2883
2879
|
# occurrence of a match; trailing empty substrings are not returned:
|
|
2884
2880
|
#
|
|
2885
2881
|
# 'abracadabra'.split(/ab/) # => ["", "racad", "ra"]
|
|
@@ -2892,11 +2888,9 @@ class String
|
|
|
2892
2888
|
#
|
|
2893
2889
|
# '1:2:3'.split(/(:)()()/, 2) # => ["1", ":", "", "", "2:3"]
|
|
2894
2890
|
#
|
|
2895
|
-
# As seen above, if `limit` is `
|
|
2896
|
-
# returned; the same is true if `limit` is zero:
|
|
2891
|
+
# As seen above, if `limit` is `0`, trailing empty substrings are not returned:
|
|
2897
2892
|
#
|
|
2898
2893
|
# 'aaabcdaaa'.split('a') => ["", "", "", "bcd"]
|
|
2899
|
-
# 'aaabcdaaa'.split('a', 0) # => ["", "", "", "bcd"]
|
|
2900
2894
|
#
|
|
2901
2895
|
# If `limit` is positive integer `n`, no more than `n - 1-` splits occur, so
|
|
2902
2896
|
# that at most `n` substrings are returned, and trailing empty substrings are
|
|
@@ -2911,7 +2905,7 @@ class String
|
|
|
2911
2905
|
# Note that if `field_sep` is a Regexp containing groups, their matches are in
|
|
2912
2906
|
# the returned array, but do not count toward the limit.
|
|
2913
2907
|
#
|
|
2914
|
-
# If `limit` is negative, it behaves the same as if `limit` was
|
|
2908
|
+
# If `limit` is negative, it behaves the same as if `limit` was zero, meaning
|
|
2915
2909
|
# that there is no limit, and trailing empty substrings are included:
|
|
2916
2910
|
#
|
|
2917
2911
|
# 'aaabcdaaa'.split('a', -1) # => ["", "", "", "bcd", "", "", ""]
|
|
@@ -2970,7 +2964,6 @@ class String
|
|
|
2970
2964
|
# * `string_or_regexp` itself, if it is a Regexp.
|
|
2971
2965
|
# * `Regexp.quote(string_or_regexp)`, if `string_or_regexp` is a string.
|
|
2972
2966
|
#
|
|
2973
|
-
#
|
|
2974
2967
|
# Returns `true` if any pattern matches the beginning, `false` otherwise:
|
|
2975
2968
|
#
|
|
2976
2969
|
# 'hello'.start_with?('hell') # => true
|
|
@@ -3031,8 +3024,8 @@ class String
|
|
|
3031
3024
|
# - sub!(pattern, replacement) -> self or nil
|
|
3032
3025
|
# - sub!(pattern) {|match| ... } -> self or nil
|
|
3033
3026
|
# -->
|
|
3034
|
-
#
|
|
3035
|
-
#
|
|
3027
|
+
# Replaces the first occurrence (not all occurrences) of the given `pattern` on
|
|
3028
|
+
# `self`; returns `self` if a replacement occurred, `nil` otherwise.
|
|
3036
3029
|
#
|
|
3037
3030
|
# See [Substitution Methods](rdoc-ref:String@Substitution+Methods).
|
|
3038
3031
|
#
|
|
@@ -3092,7 +3085,7 @@ class String
|
|
|
3092
3085
|
# s = '99zz99zz'
|
|
3093
3086
|
# s.succ # => "100aa00aa"
|
|
3094
3087
|
#
|
|
3095
|
-
# The successor to an empty String is a new empty String
|
|
3088
|
+
# The successor to an empty `String` is a new empty `String`:
|
|
3096
3089
|
#
|
|
3097
3090
|
# ''.succ # => ""
|
|
3098
3091
|
#
|
|
@@ -3278,19 +3271,19 @@ class String
|
|
|
3278
3271
|
# rdoc-file=string.c
|
|
3279
3272
|
# - to_s -> self or string
|
|
3280
3273
|
# -->
|
|
3281
|
-
# Returns `self` if `self` is a String
|
|
3282
|
-
# `self` is a subclass of String
|
|
3274
|
+
# Returns `self` if `self` is a `String`, or `self` converted to a `String` if
|
|
3275
|
+
# `self` is a subclass of `String`.
|
|
3283
3276
|
#
|
|
3284
3277
|
def to_s: () -> String
|
|
3285
3278
|
|
|
3286
3279
|
# <!-- rdoc-file=string.c -->
|
|
3287
|
-
# Returns `self` if `self` is a String
|
|
3288
|
-
# `self` is a subclass of String
|
|
3280
|
+
# Returns `self` if `self` is a `String`, or `self` converted to a `String` if
|
|
3281
|
+
# `self` is a subclass of `String`.
|
|
3289
3282
|
#
|
|
3290
3283
|
alias to_str to_s
|
|
3291
3284
|
|
|
3292
3285
|
# <!-- rdoc-file=string.c -->
|
|
3293
|
-
# Returns the Symbol corresponding to *str*, creating the symbol if it did not
|
|
3286
|
+
# Returns the `Symbol` corresponding to *str*, creating the symbol if it did not
|
|
3294
3287
|
# previously exist. See Symbol#id2name.
|
|
3295
3288
|
#
|
|
3296
3289
|
# "Koala".intern #=> :Koala
|
|
@@ -3320,7 +3313,6 @@ class String
|
|
|
3320
3313
|
# translated to the second character in `replacements`.
|
|
3321
3314
|
# * And so on.
|
|
3322
3315
|
#
|
|
3323
|
-
#
|
|
3324
3316
|
# Example:
|
|
3325
3317
|
#
|
|
3326
3318
|
# 'hello'.tr('el', 'ip') #=> "hippo"
|
|
@@ -3411,7 +3403,6 @@ class String
|
|
|
3411
3403
|
# * `:nfkc`: Compatibility decomposition, followed by canonical composition.
|
|
3412
3404
|
# * `:nfkd`: Compatibility decomposition.
|
|
3413
3405
|
#
|
|
3414
|
-
#
|
|
3415
3406
|
# The encoding of `self` must be one of:
|
|
3416
3407
|
#
|
|
3417
3408
|
# * Encoding::UTF_8
|
|
@@ -3423,7 +3414,6 @@ class String
|
|
|
3423
3414
|
# * Encoding::UCS_2BE
|
|
3424
3415
|
# * Encoding::UCS_4BE
|
|
3425
3416
|
#
|
|
3426
|
-
#
|
|
3427
3417
|
# Examples:
|
|
3428
3418
|
#
|
|
3429
3419
|
# "a\u0300".unicode_normalize # => "a"
|
|
@@ -3470,10 +3460,14 @@ class String
|
|
|
3470
3460
|
|
|
3471
3461
|
# <!--
|
|
3472
3462
|
# rdoc-file=pack.rb
|
|
3473
|
-
# - unpack(template, offset: 0) -> array
|
|
3463
|
+
# - unpack(template, offset: 0, &block) -> array
|
|
3474
3464
|
# -->
|
|
3475
|
-
# Extracts data from `self
|
|
3476
|
-
#
|
|
3465
|
+
# Extracts data from `self`.
|
|
3466
|
+
#
|
|
3467
|
+
# If `block` is not given, forming objects that become the elements of a new
|
|
3468
|
+
# array, and returns that array. Otherwise, yields each object.
|
|
3469
|
+
#
|
|
3470
|
+
# See [Packed Data](rdoc-ref:packed_data.rdoc).
|
|
3477
3471
|
#
|
|
3478
3472
|
def unpack: (string template, ?offset: int) -> Array[Integer | Float | String | nil]
|
|
3479
3473
|
| (string template, ?offset: int) { (Integer | Float | String | nil value) -> void } -> nil
|
|
@@ -3533,7 +3527,7 @@ class String
|
|
|
3533
3527
|
# - upto(other_string, exclusive = false) {|string| ... } -> self
|
|
3534
3528
|
# - upto(other_string, exclusive = false) -> new_enumerator
|
|
3535
3529
|
# -->
|
|
3536
|
-
# With a block given, calls the block with each String value returned by
|
|
3530
|
+
# With a block given, calls the block with each `String` value returned by
|
|
3537
3531
|
# successive calls to String#succ; the first value is `self`, the next is
|
|
3538
3532
|
# `self.succ`, and so on; the sequence terminates when value `other_string` is
|
|
3539
3533
|
# reached; returns `self`:
|