steep 0.13.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/steep.rb +16 -0
- data/lib/steep/ast/types/factory.rb +72 -37
- data/lib/steep/drivers/init.rb +5 -5
- data/lib/steep/drivers/langserver.rb +176 -6
- data/lib/steep/project/completion_provider.rb +302 -0
- data/lib/steep/project/file.rb +45 -35
- data/lib/steep/type_construction.rb +15 -8
- data/lib/steep/typing.rb +13 -2
- data/lib/steep/version.rb +1 -1
- data/smoke/alias/a.rb +1 -1
- data/smoke/regexp/b.rb +4 -4
- data/vendor/ruby-signature/Rakefile +5 -4
- data/vendor/ruby-signature/docs/CONTRIBUTING.md +3 -3
- data/vendor/ruby-signature/lib/ruby/signature/cli.rb +23 -2
- data/vendor/ruby-signature/lib/ruby/signature/parser.y +2 -1
- data/vendor/ruby-signature/lib/ruby/signature/prototype/rb.rb +3 -0
- data/vendor/ruby-signature/lib/ruby/signature/test/spy.rb +3 -0
- data/vendor/ruby-signature/stdlib/builtin/match_data.rbs +233 -103
- data/vendor/ruby-signature/stdlib/builtin/regexp.rbs +1024 -72
- data/vendor/ruby-signature/stdlib/builtin/string.rbs +1773 -649
- metadata +4 -3
@@ -1,770 +1,1894 @@
|
|
1
|
-
# A
|
2
|
-
# typically representing characters.
|
3
|
-
#
|
4
|
-
#
|
5
|
-
# Because of aliasing issues, users of strings should be aware of the
|
6
|
-
#
|
7
|
-
#
|
8
|
-
#
|
9
|
-
#
|
10
|
-
class String
|
1
|
+
# A String object holds and manipulates an arbitrary sequence of bytes,
|
2
|
+
# typically representing characters. String objects may be created using
|
3
|
+
# String::new or as literals.
|
4
|
+
#
|
5
|
+
# Because of aliasing issues, users of strings should be aware of the methods
|
6
|
+
# that modify the contents of a String object. Typically, methods with names
|
7
|
+
# ending in ``!'' modify their receiver, while those without a ``!'' return a
|
8
|
+
# new String. However, there are exceptions, such as String#[]=.
|
9
|
+
#
|
10
|
+
class String
|
11
11
|
include Comparable
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
def
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
13
|
+
# Try to convert *obj* into a String, using to_str method. Returns converted
|
14
|
+
# string or nil if *obj* cannot be converted for any reason.
|
15
|
+
#
|
16
|
+
# String.try_convert("str") #=> "str"
|
17
|
+
# String.try_convert(/re/) #=> nil
|
18
|
+
#
|
19
|
+
def self.try_convert: (untyped obj) -> String?
|
20
|
+
|
21
|
+
public
|
22
|
+
|
23
|
+
# Format---Uses *str* as a format specification, and returns the result of
|
24
|
+
# applying it to *arg*. If the format specification contains more than one
|
25
|
+
# substitution, then *arg* must be an Array or Hash containing the values to be
|
26
|
+
# substituted. See Kernel#sprintf for details of the format string.
|
27
|
+
#
|
28
|
+
# "%05d" % 123 #=> "00123"
|
29
|
+
# "%-5s: %016x" % [ "ID", self.object_id ] #=> "ID : 00002b054ec93168"
|
30
|
+
# "foo = %{foo}" % { :foo => 'bar' } #=> "foo = bar"
|
31
|
+
#
|
32
|
+
def %: (Hash[Symbol, untyped]) -> String
|
33
|
+
| (Array[untyped]) -> String
|
34
|
+
| (untyped arg) -> String
|
35
|
+
|
36
|
+
# Copy --- Returns a new String containing `integer` copies of the receiver.
|
37
|
+
# `integer` must be greater than or equal to 0.
|
38
|
+
#
|
39
|
+
# "Ho! " * 3 #=> "Ho! Ho! Ho! "
|
40
|
+
# "Ho! " * 0 #=> ""
|
41
|
+
#
|
42
|
+
def *: (int n) -> String
|
43
|
+
|
44
|
+
# Concatenation---Returns a new String containing *other_str* concatenated to
|
45
|
+
# *str*.
|
46
|
+
#
|
47
|
+
# "Hello from " + self.to_s #=> "Hello from main"
|
48
|
+
#
|
49
|
+
def +: (string other_str) -> String
|
50
|
+
|
51
|
+
# If the string is frozen, then return duplicated mutable string.
|
52
|
+
#
|
53
|
+
# If the string is not frozen, then return the string itself.
|
54
|
+
#
|
55
|
+
def +@: () -> String
|
26
56
|
|
27
|
-
|
28
|
-
|
57
|
+
# Returns a frozen, possibly pre-existing copy of the string.
|
58
|
+
#
|
59
|
+
# The string will be deduplicated as long as it does not have any instance
|
60
|
+
# variables set on it.
|
61
|
+
#
|
62
|
+
def -@: () -> String
|
29
63
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
64
|
+
# Appends the given object to *str*. If the object is an Integer, it is
|
65
|
+
# considered a codepoint and converted to a character before being appended.
|
66
|
+
#
|
67
|
+
# a = "hello "
|
68
|
+
# a << "world" #=> "hello world"
|
69
|
+
# a << 33 #=> "hello world!"
|
70
|
+
#
|
71
|
+
# See also String#concat, which takes multiple arguments.
|
72
|
+
#
|
73
|
+
def <<: (string | Integer str_or_codepoint) -> String
|
74
|
+
|
75
|
+
# Comparison---Returns -1, 0, +1, or `nil` depending on whether `string` is less
|
76
|
+
# than, equal to, or greater than `other_string`.
|
77
|
+
#
|
78
|
+
# `nil` is returned if the two values are incomparable.
|
79
|
+
#
|
80
|
+
# If the strings are of different lengths, and the strings are equal when
|
81
|
+
# compared up to the shortest length, then the longer string is considered
|
82
|
+
# greater than the shorter one.
|
83
|
+
#
|
84
|
+
# `<=>` is the basis for the methods `<`, `<=`, `>`, `>=`, and `between?`,
|
85
|
+
# included from module Comparable. The method String#== does not use
|
86
|
+
# Comparable#==.
|
87
|
+
#
|
88
|
+
# "abcdef" <=> "abcde" #=> 1
|
89
|
+
# "abcdef" <=> "abcdef" #=> 0
|
90
|
+
# "abcdef" <=> "abcdefg" #=> -1
|
91
|
+
# "abcdef" <=> "ABCDEF" #=> 1
|
92
|
+
# "abcdef" <=> 1 #=> nil
|
93
|
+
#
|
94
|
+
def <=>: (untyped other) -> Integer?
|
95
|
+
|
96
|
+
# Equality---Returns whether `str` == `obj`, similar to Object#==.
|
97
|
+
#
|
98
|
+
# If `obj` is not an instance of String but responds to `to_str`, then the two
|
99
|
+
# strings are compared using `obj.==`.
|
100
|
+
#
|
101
|
+
# Otherwise, returns similarly to String#eql?, comparing length and content.
|
102
|
+
#
|
103
|
+
def ==: (untyped obj) -> bool
|
104
|
+
|
105
|
+
# Equality---Returns whether `str` == `obj`, similar to Object#==.
|
106
|
+
#
|
107
|
+
# If `obj` is not an instance of String but responds to `to_str`, then the two
|
108
|
+
# strings are compared using `obj.==`.
|
109
|
+
#
|
110
|
+
# Otherwise, returns similarly to String#eql?, comparing length and content.
|
111
|
+
#
|
112
|
+
def ===: (untyped obj) -> bool
|
113
|
+
|
114
|
+
# Match---If *obj* is a Regexp, uses it as a pattern to match against the
|
115
|
+
# receiver, and returns the position the match starts, or `nil` if there is no
|
116
|
+
# match. Otherwise, invokes *obj.=~*, passing the string as an argument. The
|
117
|
+
# default Object#=~ (deprecated) returns `nil`.
|
118
|
+
#
|
119
|
+
# "cat o' 9 tails" =~ /\d/ #=> 7
|
120
|
+
# "cat o' 9 tails" =~ 9 #=> nil
|
121
|
+
#
|
122
|
+
# Note that `string =~ regexp` is not the same as `regexp =~ string`. Strings
|
123
|
+
# captured from named capture groups are assigned to local variables only in the
|
124
|
+
# second case.
|
125
|
+
#
|
126
|
+
# "no. 9" =~ /(?<number>\d+)/
|
127
|
+
# number #=> nil (not assigned)
|
128
|
+
# /(?<number>\d+)/ =~ "no. 9"
|
129
|
+
# number #=> "9"
|
130
|
+
#
|
131
|
+
def =~: (untyped obj) -> Integer?
|
132
|
+
|
133
|
+
# Element Reference --- If passed a single `index`, returns a substring of one
|
134
|
+
# character at that index. If passed a `start` index and a `length`, returns a
|
135
|
+
# substring containing `length` characters starting at the `start` index. If
|
136
|
+
# passed a `range`, its beginning and end are interpreted as offsets delimiting
|
137
|
+
# the substring to be returned.
|
138
|
+
#
|
139
|
+
# In these three cases, if an index is negative, it is counted from the end of
|
140
|
+
# the string. For the `start` and `range` cases the starting index is just
|
141
|
+
# before a character and an index matching the string's size. Additionally, an
|
142
|
+
# empty string is returned when the starting index for a character range is at
|
143
|
+
# the end of the string.
|
144
|
+
#
|
145
|
+
# Returns `nil` if the initial index falls outside the string or the length is
|
146
|
+
# negative.
|
147
|
+
#
|
148
|
+
# If a `Regexp` is supplied, the matching portion of the string is returned. If
|
149
|
+
# a `capture` follows the regular expression, which may be a capture group index
|
150
|
+
# or name, follows the regular expression that component of the MatchData is
|
151
|
+
# returned instead.
|
152
|
+
#
|
153
|
+
# If a `match_str` is given, that string is returned if it occurs in the string.
|
154
|
+
#
|
155
|
+
# Returns `nil` if the regular expression does not match or the match string
|
156
|
+
# cannot be found.
|
157
|
+
#
|
158
|
+
# a = "hello there"
|
159
|
+
#
|
160
|
+
# a[1] #=> "e"
|
161
|
+
# a[2, 3] #=> "llo"
|
162
|
+
# a[2..3] #=> "ll"
|
163
|
+
#
|
164
|
+
# a[-3, 2] #=> "er"
|
165
|
+
# a[7..-2] #=> "her"
|
166
|
+
# a[-4..-2] #=> "her"
|
167
|
+
# a[-2..-4] #=> ""
|
168
|
+
#
|
169
|
+
# a[11, 0] #=> ""
|
170
|
+
# a[11] #=> nil
|
171
|
+
# a[12, 0] #=> nil
|
172
|
+
# a[12..-1] #=> nil
|
173
|
+
#
|
174
|
+
# a[/[aeiou](.)\1/] #=> "ell"
|
175
|
+
# a[/[aeiou](.)\1/, 0] #=> "ell"
|
176
|
+
# a[/[aeiou](.)\1/, 1] #=> "l"
|
177
|
+
# a[/[aeiou](.)\1/, 2] #=> nil
|
178
|
+
#
|
179
|
+
# a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] #=> "l"
|
180
|
+
# a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "vowel"] #=> "e"
|
181
|
+
#
|
182
|
+
# a["lo"] #=> "lo"
|
183
|
+
# a["bye"] #=> nil
|
184
|
+
#
|
185
|
+
def []: (int index) -> String?
|
186
|
+
| (int start, int length) -> String?
|
187
|
+
| (Range[Integer] | Range[Integer?] range) -> String?
|
188
|
+
| (Regexp regexp) -> String?
|
189
|
+
| (Regexp regexp, int | String capture) -> String?
|
190
|
+
| (String match_str) -> String?
|
191
|
+
|
192
|
+
# Element Assignment---Replaces some or all of the content of *str*. The portion
|
193
|
+
# of the string affected is determined using the same criteria as String#[]. If
|
194
|
+
# the replacement string is not the same length as the text it is replacing, the
|
195
|
+
# string will be adjusted accordingly. If the regular expression or string is
|
196
|
+
# used as the index doesn't match a position in the string, IndexError is
|
197
|
+
# raised. If the regular expression form is used, the optional second Integer
|
198
|
+
# allows you to specify which portion of the match to replace (effectively using
|
199
|
+
# the MatchData indexing rules. The forms that take an Integer will raise an
|
200
|
+
# IndexError if the value is out of range; the Range form will raise a
|
201
|
+
# RangeError, and the Regexp and String will raise an IndexError on negative
|
202
|
+
# match.
|
203
|
+
#
|
204
|
+
def []=: (int pos, String new_str) -> String
|
205
|
+
| (int begin_pos, int end_pos, String new_str) -> String
|
206
|
+
| (Range[Integer] | Range[Integer?] range, String new_str) -> String
|
207
|
+
| (Regexp regexp, String new_str) -> String
|
208
|
+
| (Regexp regexp, int capture, String new_str) -> String
|
209
|
+
| (Regexp regexp, String name, String new_str) -> String
|
210
|
+
| (String other_str, String new_str) -> String
|
35
211
|
|
36
212
|
# Returns true for a string which has only ASCII characters.
|
37
|
-
#
|
38
|
-
#
|
39
|
-
#
|
40
|
-
#
|
41
|
-
# ```
|
213
|
+
#
|
214
|
+
# "abc".force_encoding("UTF-8").ascii_only? #=> true
|
215
|
+
# "abc\u{6666}".force_encoding("UTF-8").ascii_only? #=> false
|
216
|
+
#
|
42
217
|
def ascii_only?: () -> bool
|
43
218
|
|
44
219
|
# Returns a copied string whose encoding is ASCII-8BIT.
|
220
|
+
#
|
45
221
|
def b: () -> String
|
46
222
|
|
47
|
-
# Returns an array of bytes in *str
|
48
|
-
# `str.each_byte.to_a
|
49
|
-
#
|
223
|
+
# Returns an array of bytes in *str*. This is a shorthand for
|
224
|
+
# `str.each_byte.to_a`.
|
225
|
+
#
|
50
226
|
# If a block is given, which is a deprecated form, works the same as
|
51
|
-
# `each_byte
|
52
|
-
|
227
|
+
# `each_byte`.
|
228
|
+
#
|
229
|
+
def bytes: () -> Array[Integer]
|
230
|
+
| () { (Integer byte) -> void } -> String
|
53
231
|
|
54
232
|
# Returns the length of `str` in bytes.
|
55
|
-
#
|
233
|
+
#
|
56
234
|
# "\x80\u3042".bytesize #=> 4
|
57
235
|
# "hello".bytesize #=> 5
|
236
|
+
#
|
58
237
|
def bytesize: () -> Integer
|
59
238
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
#
|
67
|
-
#
|
68
|
-
#
|
69
|
-
#
|
70
|
-
#
|
71
|
-
#
|
72
|
-
#
|
73
|
-
#
|
239
|
+
# Byte Reference---If passed a single Integer, returns a substring of one byte
|
240
|
+
# at that position. If passed two Integer objects, returns a substring starting
|
241
|
+
# at the offset given by the first, and a length given by the second. If given a
|
242
|
+
# Range, a substring containing bytes at offsets given by the range is returned.
|
243
|
+
# In all three cases, if an offset is negative, it is counted from the end of
|
244
|
+
# *str*. Returns `nil` if the initial offset falls outside the string, the
|
245
|
+
# length is negative, or the beginning of the range is greater than the end. The
|
246
|
+
# encoding of the resulted string keeps original encoding.
|
247
|
+
#
|
248
|
+
# "hello".byteslice(1) #=> "e"
|
249
|
+
# "hello".byteslice(-1) #=> "o"
|
250
|
+
# "hello".byteslice(1, 2) #=> "el"
|
251
|
+
# "\x80\u3042".byteslice(1, 3) #=> "\u3042"
|
252
|
+
# "\x03\u3042\xff".byteslice(1..3) #=> "\u3042"
|
253
|
+
#
|
254
|
+
def byteslice: (int start, ?int length) -> String?
|
255
|
+
| (Range[Integer] | Range[Integer?] range) -> String?
|
256
|
+
|
257
|
+
# Returns a copy of *str* with the first character converted to uppercase and
|
258
|
+
# the remainder to lowercase.
|
259
|
+
#
|
260
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
261
|
+
#
|
262
|
+
# "hello".capitalize #=> "Hello"
|
263
|
+
# "HELLO".capitalize #=> "Hello"
|
264
|
+
# "123ABC".capitalize #=> "123abc"
|
265
|
+
#
|
74
266
|
def capitalize: () -> String
|
267
|
+
| (:ascii | :lithuanian | :turkic) -> String
|
268
|
+
| (:lithuanian, :turkic) -> String
|
269
|
+
| (:turkic, :lithuanian) -> String
|
75
270
|
|
76
271
|
# Modifies *str* by converting the first character to uppercase and the
|
77
|
-
# remainder to lowercase. Returns `nil` if no changes are made. There is
|
78
|
-
#
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
84
|
-
#
|
85
|
-
#
|
86
|
-
#
|
87
|
-
#
|
88
|
-
# a.capitalize! #=> "Hello"
|
89
|
-
# a #=> "Hello"
|
90
|
-
# a.capitalize! #=> nil
|
91
|
-
# ```
|
272
|
+
# remainder to lowercase. Returns `nil` if no changes are made. There is an
|
273
|
+
# exception for modern Georgian (mkhedruli/MTAVRULI), where the result is the
|
274
|
+
# same as for String#downcase, to avoid mixed case.
|
275
|
+
#
|
276
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
277
|
+
#
|
278
|
+
# a = "hello"
|
279
|
+
# a.capitalize! #=> "Hello"
|
280
|
+
# a #=> "Hello"
|
281
|
+
# a.capitalize! #=> nil
|
282
|
+
#
|
92
283
|
def capitalize!: () -> String?
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
#
|
99
|
-
#
|
100
|
-
#
|
284
|
+
| (:ascii | :lithuanian | :turkic) -> String?
|
285
|
+
| (:lithuanian, :turkic) -> String?
|
286
|
+
| (:turkic, :lithuanian) -> String?
|
287
|
+
|
288
|
+
# Case-insensitive version of String#<=>. Currently, case-insensitivity only
|
289
|
+
# works on characters A-Z/a-z, not all of Unicode. This is different from
|
290
|
+
# String#casecmp?.
|
291
|
+
#
|
292
|
+
# "aBcDeF".casecmp("abcde") #=> 1
|
293
|
+
# "aBcDeF".casecmp("abcdef") #=> 0
|
294
|
+
# "aBcDeF".casecmp("abcdefg") #=> -1
|
295
|
+
# "abcdef".casecmp("ABCDEF") #=> 0
|
296
|
+
#
|
297
|
+
# `nil` is returned if the two strings have incompatible encodings, or if
|
298
|
+
# `other_str` is not a string.
|
299
|
+
#
|
300
|
+
# "foo".casecmp(2) #=> nil
|
301
|
+
# "\u{e4 f6 fc}".encode("ISO-8859-1").casecmp("\u{c4 d6 dc}") #=> nil
|
302
|
+
#
|
303
|
+
def casecmp: (untyped other) -> Integer?
|
304
|
+
|
305
|
+
# Returns `true` if `str` and `other_str` are equal after Unicode case folding,
|
306
|
+
# `false` if they are not equal.
|
307
|
+
#
|
308
|
+
# "aBcDeF".casecmp?("abcde") #=> false
|
309
|
+
# "aBcDeF".casecmp?("abcdef") #=> true
|
310
|
+
# "aBcDeF".casecmp?("abcdefg") #=> false
|
311
|
+
# "abcdef".casecmp?("ABCDEF") #=> true
|
312
|
+
# "\u{e4 f6 fc}".casecmp?("\u{c4 d6 dc}") #=> true
|
313
|
+
#
|
314
|
+
# `nil` is returned if the two strings have incompatible encodings, or if
|
315
|
+
# `other_str` is not a string.
|
316
|
+
#
|
317
|
+
# "foo".casecmp?(2) #=> nil
|
318
|
+
# "\u{e4 f6 fc}".encode("ISO-8859-1").casecmp?("\u{c4 d6 dc}") #=> nil
|
319
|
+
#
|
320
|
+
def casecmp?: (untyped other) -> bool
|
321
|
+
|
322
|
+
# Centers `str` in `width`. If `width` is greater than the length of `str`,
|
323
|
+
# returns a new String of length `width` with `str` centered and padded with
|
324
|
+
# `padstr`; otherwise, returns `str`.
|
325
|
+
#
|
326
|
+
# "hello".center(4) #=> "hello"
|
327
|
+
# "hello".center(20) #=> " hello "
|
328
|
+
# "hello".center(20, '123') #=> "1231231hello12312312"
|
329
|
+
#
|
330
|
+
def center: (int width, ?string padstr) -> String
|
331
|
+
|
332
|
+
# Returns an array of characters in *str*. This is a shorthand for
|
333
|
+
# `str.each_char.to_a`.
|
334
|
+
#
|
101
335
|
# If a block is given, which is a deprecated form, works the same as
|
102
|
-
# `each_char
|
336
|
+
# `each_char`.
|
337
|
+
#
|
103
338
|
def chars: () -> Array[String]
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
#
|
110
|
-
#
|
111
|
-
#
|
112
|
-
#
|
113
|
-
#
|
114
|
-
#
|
115
|
-
#
|
116
|
-
#
|
117
|
-
#
|
118
|
-
#
|
119
|
-
#
|
120
|
-
#
|
121
|
-
#
|
339
|
+
| () { (String char) -> void } -> String
|
340
|
+
|
341
|
+
# Returns a new String with the given record separator removed from the end of
|
342
|
+
# *str* (if present). If `$/` has not been changed from the default Ruby record
|
343
|
+
# separator, then `chomp` also removes carriage return characters (that is it
|
344
|
+
# will remove `\n`, `\r`, and `\r\n`). If `$/` is an empty string, it will
|
345
|
+
# remove all trailing newlines from the string.
|
346
|
+
#
|
347
|
+
# "hello".chomp #=> "hello"
|
348
|
+
# "hello\n".chomp #=> "hello"
|
349
|
+
# "hello\r\n".chomp #=> "hello"
|
350
|
+
# "hello\n\r".chomp #=> "hello\n"
|
351
|
+
# "hello\r".chomp #=> "hello"
|
352
|
+
# "hello \n there".chomp #=> "hello \n there"
|
353
|
+
# "hello".chomp("llo") #=> "he"
|
354
|
+
# "hello\r\n\r\n".chomp('') #=> "hello"
|
355
|
+
# "hello\r\n\r\r\n".chomp('') #=> "hello\r\n\r"
|
356
|
+
#
|
357
|
+
def chomp: (?string separator) -> String
|
358
|
+
|
359
|
+
# Modifies *str* in place as described for String#chomp, returning *str*, or
|
360
|
+
# `nil` if no modifications were made.
|
361
|
+
#
|
362
|
+
def chomp!: (?string separator) -> String?
|
363
|
+
|
364
|
+
# Returns a new String with the last character removed. If the string ends with
|
365
|
+
# `\r\n`, both characters are removed. Applying `chop` to an empty string
|
366
|
+
# returns an empty string. String#chomp is often a safer alternative, as it
|
367
|
+
# leaves the string unchanged if it doesn't end in a record separator.
|
368
|
+
#
|
369
|
+
# "string\r\n".chop #=> "string"
|
370
|
+
# "string\n\r".chop #=> "string\n"
|
371
|
+
# "string\n".chop #=> "string"
|
372
|
+
# "string".chop #=> "strin"
|
373
|
+
# "x".chop.chop #=> ""
|
374
|
+
#
|
122
375
|
def chop: () -> String
|
123
376
|
|
124
|
-
# Processes *str* as for
|
125
|
-
#
|
377
|
+
# Processes *str* as for String#chop, returning *str*, or `nil` if *str* is the
|
378
|
+
# empty string. See also String#chomp!.
|
379
|
+
#
|
126
380
|
def chop!: () -> String?
|
127
381
|
|
128
382
|
# Returns a one-character string at the beginning of the string.
|
129
|
-
#
|
130
|
-
#
|
131
|
-
#
|
132
|
-
#
|
133
|
-
# ```
|
383
|
+
#
|
384
|
+
# a = "abcde"
|
385
|
+
# a.chr #=> "a"
|
386
|
+
#
|
134
387
|
def chr: () -> String
|
135
388
|
|
136
389
|
# Makes string empty.
|
137
|
-
#
|
138
|
-
#
|
139
|
-
#
|
140
|
-
#
|
141
|
-
# ```
|
390
|
+
#
|
391
|
+
# a = "abcde"
|
392
|
+
# a.clear #=> ""
|
393
|
+
#
|
142
394
|
def clear: () -> String
|
143
395
|
|
144
|
-
# Returns an array of the
|
145
|
-
#
|
146
|
-
#
|
396
|
+
# Returns an array of the Integer ordinals of the characters in *str*. This is
|
397
|
+
# a shorthand for `str.each_codepoint.to_a`.
|
398
|
+
#
|
147
399
|
# If a block is given, which is a deprecated form, works the same as
|
148
|
-
# `each_codepoint
|
400
|
+
# `each_codepoint`.
|
401
|
+
#
|
149
402
|
def codepoints: () -> ::Array[Integer]
|
150
|
-
| () { () ->
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
403
|
+
| () { (Integer codepoint) -> void } -> String
|
404
|
+
|
405
|
+
# Concatenates the given object(s) to *str*. If an object is an Integer, it is
|
406
|
+
# considered a codepoint and converted to a character before concatenation.
|
407
|
+
#
|
408
|
+
# `concat` can take multiple arguments, and all the arguments are concatenated
|
409
|
+
# in order.
|
410
|
+
#
|
411
|
+
# a = "hello "
|
412
|
+
# a.concat("world", 33) #=> "hello world!"
|
413
|
+
# a #=> "hello world!"
|
414
|
+
#
|
415
|
+
# b = "sn"
|
416
|
+
# b.concat("_", b, "_", b) #=> "sn_sn_sn"
|
417
|
+
#
|
418
|
+
# See also String#<<, which takes a single argument.
|
419
|
+
#
|
420
|
+
def concat: (*string | Integer str_or_codepoint) -> String
|
421
|
+
|
422
|
+
# Each `other_str` parameter defines a set of characters to count. The
|
423
|
+
# intersection of these sets defines the characters to count in `str`. Any
|
424
|
+
# `other_str` that starts with a caret `^` is negated. The sequence `c1-c2`
|
425
|
+
# means all characters between c1 and c2. The backslash character `\` can be
|
426
|
+
# used to escape `^` or `-` and is otherwise ignored unless it appears at the
|
427
|
+
# end of a sequence or the end of a `other_str`.
|
428
|
+
#
|
429
|
+
# a = "hello world"
|
430
|
+
# a.count "lo" #=> 5
|
431
|
+
# a.count "lo", "o" #=> 2
|
432
|
+
# a.count "hello", "^l" #=> 4
|
433
|
+
# a.count "ej-m" #=> 4
|
434
|
+
#
|
435
|
+
# "hello^world".count "\\^aeiou" #=> 4
|
436
|
+
# "hello-world".count "a\\-eo" #=> 4
|
437
|
+
#
|
438
|
+
# c = "hello world\\r\\n"
|
439
|
+
# c.count "\\" #=> 2
|
440
|
+
# c.count "\\A" #=> 0
|
441
|
+
# c.count "X-\\w" #=> 3
|
442
|
+
#
|
443
|
+
def count: (string other_str, *string other_strs) -> Integer
|
444
|
+
|
445
|
+
# Returns the string generated by calling `crypt(3)` standard library function
|
446
|
+
# with `str` and `salt_str`, in this order, as its arguments. Please do not use
|
447
|
+
# this method any longer. It is legacy; provided only for backward
|
448
|
+
# compatibility with ruby scripts in earlier days. It is bad to use in
|
449
|
+
# contemporary programs for several reasons:
|
450
|
+
#
|
451
|
+
# * Behaviour of C's `crypt(3)` depends on the OS it is run. The generated
|
452
|
+
# string lacks data portability.
|
453
|
+
#
|
454
|
+
# * On some OSes such as Mac OS, `crypt(3)` never fails (i.e. silently ends up
|
455
|
+
# in unexpected results).
|
456
|
+
#
|
457
|
+
# * On some OSes such as Mac OS, `crypt(3)` is not thread safe.
|
458
|
+
#
|
459
|
+
# * So-called "traditional" usage of `crypt(3)` is very very very weak.
|
460
|
+
# According to its manpage, Linux's traditional `crypt(3)` output has only
|
461
|
+
# 2**56 variations; too easy to brute force today. And this is the default
|
462
|
+
# behaviour.
|
463
|
+
#
|
464
|
+
# * In order to make things robust some OSes implement so-called "modular"
|
465
|
+
# usage. To go through, you have to do a complex build-up of the `salt_str`
|
466
|
+
# parameter, by hand. Failure in generation of a proper salt string tends
|
467
|
+
# not to yield any errors; typos in parameters are normally not detectable.
|
468
|
+
#
|
469
|
+
# * For instance, in the following example, the second invocation of
|
470
|
+
# String#crypt is wrong; it has a typo in "round=" (lacks "s"). However
|
471
|
+
# the call does not fail and something unexpected is generated.
|
472
|
+
#
|
473
|
+
# "foo".crypt("$5$rounds=1000$salt$") # OK, proper usage
|
474
|
+
# "foo".crypt("$5$round=1000$salt$") # Typo not detected
|
475
|
+
#
|
476
|
+
#
|
477
|
+
# * Even in the "modular" mode, some hash functions are considered archaic and
|
478
|
+
# no longer recommended at all; for instance module `$1$` is officially
|
479
|
+
# abandoned by its author: see http://phk.freebsd.dk/sagas/md5crypt_eol.html
|
480
|
+
# . For another instance module `$3$` is considered completely broken: see
|
481
|
+
# the manpage of FreeBSD.
|
482
|
+
#
|
483
|
+
# * On some OS such as Mac OS, there is no modular mode. Yet, as written
|
484
|
+
# above, `crypt(3)` on Mac OS never fails. This means even if you build up a
|
485
|
+
# proper salt string it generates a traditional DES hash anyways, and there
|
486
|
+
# is no way for you to be aware of.
|
487
|
+
#
|
488
|
+
# "foo".crypt("$5$rounds=1000$salt$") # => "$5fNPQMxC5j6."
|
489
|
+
#
|
490
|
+
#
|
491
|
+
# If for some reason you cannot migrate to other secure contemporary password
|
492
|
+
# hashing algorithms, install the string-crypt gem and `require 'string/crypt'`
|
493
|
+
# to continue using it.
|
494
|
+
#
|
495
|
+
def crypt: (string salt_str) -> String
|
496
|
+
|
497
|
+
# Returns a copy of *str* with all characters in the intersection of its
|
498
|
+
# arguments deleted. Uses the same rules for building the set of characters as
|
499
|
+
# String#count.
|
500
|
+
#
|
501
|
+
# "hello".delete "l","lo" #=> "heo"
|
502
|
+
# "hello".delete "lo" #=> "he"
|
503
|
+
# "hello".delete "aeiou", "^e" #=> "hell"
|
504
|
+
# "hello".delete "ej-m" #=> "ho"
|
505
|
+
#
|
506
|
+
def delete: (string other_str, *string other_strs) -> String
|
507
|
+
|
508
|
+
# Performs a `delete` operation in place, returning *str*, or `nil` if *str* was
|
509
|
+
# not modified.
|
510
|
+
#
|
511
|
+
def delete!: (string other_str, *string other_strs) -> String?
|
512
|
+
|
513
|
+
# Returns a copy of *str* with leading `prefix` deleted.
|
514
|
+
#
|
515
|
+
# "hello".delete_prefix("hel") #=> "lo"
|
516
|
+
# "hello".delete_prefix("llo") #=> "hello"
|
517
|
+
#
|
518
|
+
def delete_prefix: (string prefix) -> String
|
519
|
+
|
520
|
+
# Deletes leading `prefix` from *str*, returning `nil` if no change was made.
|
521
|
+
#
|
522
|
+
# "hello".delete_prefix!("hel") #=> "lo"
|
523
|
+
# "hello".delete_prefix!("llo") #=> nil
|
524
|
+
#
|
525
|
+
def delete_prefix!: (string prefix) -> String?
|
526
|
+
|
527
|
+
# Returns a copy of *str* with trailing `suffix` deleted.
|
528
|
+
#
|
529
|
+
# "hello".delete_suffix("llo") #=> "he"
|
530
|
+
# "hello".delete_suffix("hel") #=> "hello"
|
531
|
+
#
|
532
|
+
def delete_suffix: (string suffix) -> String
|
533
|
+
|
534
|
+
# Deletes trailing `suffix` from *str*, returning `nil` if no change was made.
|
535
|
+
#
|
536
|
+
# "hello".delete_suffix!("llo") #=> "he"
|
537
|
+
# "hello".delete_suffix!("hel") #=> nil
|
538
|
+
#
|
539
|
+
def delete_suffix!: (string suffix) -> String?
|
169
540
|
|
170
541
|
# Returns a copy of *str* with all uppercase letters replaced with their
|
171
|
-
# lowercase counterparts. Which letters exactly are replaced, and by which
|
172
|
-
#
|
173
|
-
#
|
174
|
-
#
|
542
|
+
# lowercase counterparts. Which letters exactly are replaced, and by which other
|
543
|
+
# letters, depends on the presence or absence of options, and on the `encoding`
|
544
|
+
# of the string.
|
545
|
+
#
|
175
546
|
# The meaning of the `options` is as follows:
|
176
|
-
#
|
177
|
-
#
|
178
|
-
#
|
179
|
-
#
|
180
|
-
#
|
181
|
-
#
|
182
|
-
#
|
183
|
-
#
|
184
|
-
#
|
185
|
-
#
|
186
|
-
#
|
187
|
-
#
|
188
|
-
#
|
189
|
-
#
|
190
|
-
#
|
191
|
-
# case
|
192
|
-
#
|
193
|
-
#
|
194
|
-
#
|
195
|
-
#
|
196
|
-
#
|
197
|
-
#
|
198
|
-
#
|
199
|
-
#
|
200
|
-
# **folding** , which is more far-reaching than Unicode case mapping.
|
201
|
-
# This option currently cannot be combined with any other option (i.e.
|
202
|
-
# there is currently no variant for turkic languages).
|
203
|
-
#
|
547
|
+
#
|
548
|
+
# No option
|
549
|
+
# : Full Unicode case mapping, suitable for most languages (see :turkic and
|
550
|
+
# :lithuanian options below for exceptions). Context-dependent case mapping
|
551
|
+
# as described in Table 3-14 of the Unicode standard is currently not
|
552
|
+
# supported.
|
553
|
+
# :ascii
|
554
|
+
# : Only the ASCII region, i.e. the characters ``A'' to ``Z'' and ``a'' to
|
555
|
+
# ``z'', are affected. This option cannot be combined with any other option.
|
556
|
+
# :turkic
|
557
|
+
# : Full Unicode case mapping, adapted for Turkic languages (Turkish,
|
558
|
+
# Azerbaijani, ...). This means that upper case I is mapped to lower case
|
559
|
+
# dotless i, and so on.
|
560
|
+
# :lithuanian
|
561
|
+
# : Currently, just full Unicode case mapping. In the future, full Unicode
|
562
|
+
# case mapping adapted for Lithuanian (keeping the dot on the lower case i
|
563
|
+
# even if there is an accent on top).
|
564
|
+
# :fold
|
565
|
+
# : Only available on `downcase` and `downcase!`. Unicode case **folding**,
|
566
|
+
# which is more far-reaching than Unicode case mapping. This option
|
567
|
+
# currently cannot be combined with any other option (i.e. there is
|
568
|
+
# currently no variant for turkic languages).
|
569
|
+
#
|
570
|
+
#
|
204
571
|
# Please note that several assumptions that are valid for ASCII-only case
|
205
|
-
# conversions do not hold for more general case conversions. For example,
|
206
|
-
#
|
207
|
-
#
|
208
|
-
# str.
|
209
|
-
#
|
210
|
-
#
|
211
|
-
#
|
212
|
-
#
|
213
|
-
#
|
214
|
-
#
|
215
|
-
#
|
216
|
-
#
|
217
|
-
#
|
218
|
-
# "hEllO".downcase #=> "hello"
|
219
|
-
# ```
|
572
|
+
# conversions do not hold for more general case conversions. For example, the
|
573
|
+
# length of the result may not be the same as the length of the input (neither
|
574
|
+
# in characters nor in bytes), some roundtrip assumptions (e.g. str.downcase ==
|
575
|
+
# str.upcase.downcase) may not apply, and Unicode normalization (i.e.
|
576
|
+
# String#unicode_normalize) is not necessarily maintained by case mapping
|
577
|
+
# operations.
|
578
|
+
#
|
579
|
+
# Non-ASCII case mapping/folding is currently supported for UTF-8, UTF-16BE/LE,
|
580
|
+
# UTF-32BE/LE, and ISO-8859-1~16 Strings/Symbols. This support will be extended
|
581
|
+
# to other encodings.
|
582
|
+
#
|
583
|
+
# "hEllO".downcase #=> "hello"
|
584
|
+
#
|
220
585
|
def downcase: () -> String
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
#
|
226
|
-
#
|
586
|
+
| (:ascii | :fold | :lithuanian | :turkic) -> String
|
587
|
+
| (:lithuanian, :turkic) -> String
|
588
|
+
| (:turkic, :lithuanian) -> String
|
589
|
+
|
590
|
+
# Downcases the contents of *str*, returning `nil` if no changes were made.
|
591
|
+
#
|
592
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
593
|
+
#
|
227
594
|
def downcase!: () -> String?
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
#
|
233
|
-
#
|
234
|
-
#
|
595
|
+
| (:ascii | :fold | :lithuanian | :turkic) -> String?
|
596
|
+
| (:lithuanian, :turkic) -> String?
|
597
|
+
| (:turkic, :lithuanian) -> String?
|
598
|
+
|
599
|
+
# Returns a quoted version of the string with all non-printing characters
|
600
|
+
# replaced by `\xHH` notation and all special characters escaped.
|
601
|
+
#
|
602
|
+
# This method can be used for round-trip: if the resulting `new_str` is eval'ed,
|
603
|
+
# it will produce the original string.
|
604
|
+
#
|
605
|
+
# "hello \n ''".dump #=> "\"hello \\n ''\""
|
606
|
+
# "\f\x00\xff\\\"".dump #=> "\"\\f\\x00\\xFF\\\\\\\"\""
|
607
|
+
#
|
608
|
+
# See also String#undump.
|
609
|
+
#
|
235
610
|
def dump: () -> String
|
236
611
|
|
237
|
-
|
612
|
+
# Passes each byte in *str* to the given block, or returns an enumerator if no
|
613
|
+
# block is given.
|
614
|
+
#
|
615
|
+
# "hello".each_byte {|c| print c, ' ' }
|
616
|
+
#
|
617
|
+
# *produces:*
|
618
|
+
#
|
619
|
+
# 104 101 108 108 111
|
620
|
+
#
|
621
|
+
def each_byte: () { (Integer byte) -> void } -> self
|
238
622
|
| () -> ::Enumerator[Integer, self]
|
239
623
|
|
240
|
-
|
624
|
+
# Passes each character in *str* to the given block, or returns an enumerator if
|
625
|
+
# no block is given.
|
626
|
+
#
|
627
|
+
# "hello".each_char {|c| print c, ' ' }
|
628
|
+
#
|
629
|
+
# *produces:*
|
630
|
+
#
|
631
|
+
# h e l l o
|
632
|
+
#
|
633
|
+
def each_char: () { (String char) -> void } -> self
|
241
634
|
| () -> ::Enumerator[String, self]
|
242
635
|
|
243
|
-
|
636
|
+
# Passes the Integer ordinal of each character in *str*, also known as a
|
637
|
+
# *codepoint* when applied to Unicode strings to the given block. For encodings
|
638
|
+
# other than UTF-8/UTF-16(BE|LE)/UTF-32(BE|LE), values are directly derived from
|
639
|
+
# the binary representation of each character.
|
640
|
+
#
|
641
|
+
# If no block is given, an enumerator is returned instead.
|
642
|
+
#
|
643
|
+
# "hello\u0639".each_codepoint {|c| print c, ' ' }
|
644
|
+
#
|
645
|
+
# *produces:*
|
646
|
+
#
|
647
|
+
# 104 101 108 108 111 1593
|
648
|
+
#
|
649
|
+
def each_codepoint: () { (Integer codepoint) -> void } -> self
|
244
650
|
| () -> ::Enumerator[Integer, self]
|
245
651
|
|
246
|
-
|
247
|
-
|
652
|
+
# Passes each grapheme cluster in *str* to the given block, or returns an
|
653
|
+
# enumerator if no block is given. Unlike String#each_char, this enumerates by
|
654
|
+
# grapheme clusters defined by Unicode Standard Annex #29
|
655
|
+
# http://unicode.org/reports/tr29/
|
656
|
+
#
|
657
|
+
# "a\u0300".each_char.to_a.size #=> 2
|
658
|
+
# "a\u0300".each_grapheme_cluster.to_a.size #=> 1
|
659
|
+
#
|
660
|
+
def each_grapheme_cluster: () { (String grapheme) -> void } -> self
|
661
|
+
| () -> ::Enumerator[String, self]
|
662
|
+
|
663
|
+
# Splits *str* using the supplied parameter as the record separator (`$/` by
|
664
|
+
# default), passing each substring in turn to the supplied block. If a
|
665
|
+
# zero-length record separator is supplied, the string is split into paragraphs
|
666
|
+
# delimited by multiple successive newlines.
|
667
|
+
#
|
668
|
+
# If `chomp` is `true`, `separator` will be removed from the end of each line.
|
669
|
+
#
|
670
|
+
# If no block is given, an enumerator is returned instead.
|
671
|
+
#
|
672
|
+
# "hello\nworld".each_line {|s| p s}
|
673
|
+
# # prints:
|
674
|
+
# # "hello\n"
|
675
|
+
# # "world"
|
676
|
+
#
|
677
|
+
# "hello\nworld".each_line('l') {|s| p s}
|
678
|
+
# # prints:
|
679
|
+
# # "hel"
|
680
|
+
# # "l"
|
681
|
+
# # "o\nworl"
|
682
|
+
# # "d"
|
683
|
+
#
|
684
|
+
# "hello\n\n\nworld".each_line('') {|s| p s}
|
685
|
+
# # prints
|
686
|
+
# # "hello\n\n"
|
687
|
+
# # "world"
|
688
|
+
#
|
689
|
+
# "hello\nworld".each_line(chomp: true) {|s| p s}
|
690
|
+
# # prints:
|
691
|
+
# # "hello"
|
692
|
+
# # "world"
|
693
|
+
#
|
694
|
+
# "hello\nworld".each_line('l', chomp: true) {|s| p s}
|
695
|
+
# # prints:
|
696
|
+
# # "he"
|
697
|
+
# # ""
|
698
|
+
# # "o\nwor"
|
699
|
+
# # "d"
|
700
|
+
#
|
701
|
+
def each_line: (?string separator, ?chomp: bool) { (String line) -> void } -> self
|
702
|
+
| (?string separator, ?chomp: bool) -> Enumerator[String, self]
|
248
703
|
|
249
704
|
# Returns `true` if *str* has a length of zero.
|
250
|
-
#
|
251
|
-
#
|
252
|
-
# "
|
253
|
-
#
|
254
|
-
#
|
255
|
-
# ```
|
705
|
+
#
|
706
|
+
# "hello".empty? #=> false
|
707
|
+
# " ".empty? #=> false
|
708
|
+
# "".empty? #=> true
|
709
|
+
#
|
256
710
|
def empty?: () -> bool
|
257
711
|
|
258
|
-
#
|
259
|
-
#
|
712
|
+
# The first form returns a copy of `str` transcoded to encoding `encoding`. The
|
713
|
+
# second form returns a copy of `str` transcoded from src_encoding to
|
714
|
+
# dst_encoding. The last form returns a copy of `str` transcoded to
|
715
|
+
# `Encoding.default_internal`.
|
716
|
+
#
|
717
|
+
# By default, the first and second form raise Encoding::UndefinedConversionError
|
718
|
+
# for characters that are undefined in the destination encoding, and
|
719
|
+
# Encoding::InvalidByteSequenceError for invalid byte sequences in the source
|
720
|
+
# encoding. The last form by default does not raise exceptions but uses
|
721
|
+
# replacement strings.
|
722
|
+
#
|
723
|
+
# The `options` Hash gives details for conversion and can have the following
|
724
|
+
# keys:
|
725
|
+
#
|
726
|
+
# :invalid
|
727
|
+
# : If the value is `:replace`, #encode replaces invalid byte sequences in
|
728
|
+
# `str` with the replacement character. The default is to raise the
|
729
|
+
# Encoding::InvalidByteSequenceError exception
|
730
|
+
# :undef
|
731
|
+
# : If the value is `:replace`, #encode replaces characters which are
|
732
|
+
# undefined in the destination encoding with the replacement character. The
|
733
|
+
# default is to raise the Encoding::UndefinedConversionError.
|
734
|
+
# :replace
|
735
|
+
# : Sets the replacement string to the given value. The default replacement
|
736
|
+
# string is "uFFFD" for Unicode encoding forms, and "?" otherwise.
|
737
|
+
# :fallback
|
738
|
+
# : Sets the replacement string by the given object for undefined character.
|
739
|
+
# The object should be a Hash, a Proc, a Method, or an object which has []
|
740
|
+
# method. Its key is an undefined character encoded in the source encoding
|
741
|
+
# of current transcoder. Its value can be any encoding until it can be
|
742
|
+
# converted into the destination encoding of the transcoder.
|
743
|
+
# :xml
|
744
|
+
# : The value must be `:text` or `:attr`. If the value is `:text` #encode
|
745
|
+
# replaces undefined characters with their (upper-case hexadecimal) numeric
|
746
|
+
# character references. '&', '<', and '>' are converted to "&", "<",
|
747
|
+
# and ">", respectively. If the value is `:attr`, #encode also quotes the
|
748
|
+
# replacement result (using '"'), and replaces '"' with """.
|
749
|
+
# :cr_newline
|
750
|
+
# : Replaces LF ("n") with CR ("r") if value is true.
|
751
|
+
# :crlf_newline
|
752
|
+
# : Replaces LF ("n") with CRLF ("r\n") if value is true.
|
753
|
+
# :universal_newline
|
754
|
+
# : Replaces CRLF ("r\n") and CR ("r") with LF ("n") if value is true.
|
755
|
+
#
|
756
|
+
#
|
757
|
+
def encode: (?Encoding | string encoding, ?Encoding | string from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: Hash[String, String] | Proc | Method, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> String
|
758
|
+
|
759
|
+
# The first form transcodes the contents of *str* from str.encoding to
|
760
|
+
# `encoding`. The second form transcodes the contents of *str* from src_encoding
|
761
|
+
# to dst_encoding. The options Hash gives details for conversion. See
|
762
|
+
# String#encode for details. Returns the string even if no changes were made.
|
763
|
+
#
|
764
|
+
def encode!: (?Encoding | string encoding, ?Encoding | string from_encoding, ?invalid: :replace ?, ?undef: :replace ?, ?replace: String, ?fallback: Hash[String, String] | Proc | Method, ?xml: :text | :attr, ?universal_newline: true, ?cr_newline: true, ?crlf_newline: true) -> self
|
765
|
+
|
766
|
+
# Returns the Encoding object that represents the encoding of obj.
|
767
|
+
#
|
260
768
|
def encoding: () -> Encoding
|
261
769
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
def
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
770
|
+
# Returns true if `str` ends with one of the `suffixes` given.
|
771
|
+
#
|
772
|
+
# "hello".end_with?("ello") #=> true
|
773
|
+
#
|
774
|
+
# # returns true if one of the +suffixes+ matches.
|
775
|
+
# "hello".end_with?("heaven", "ello") #=> true
|
776
|
+
# "hello".end_with?("heaven", "paradise") #=> false
|
777
|
+
#
|
778
|
+
def end_with?: (*string suffixes) -> bool
|
779
|
+
|
780
|
+
# Two strings are equal if they have the same length and content.
|
781
|
+
#
|
782
|
+
def eql?: (untyped other) -> bool
|
783
|
+
|
784
|
+
# Changes the encoding to `encoding` and returns self.
|
785
|
+
#
|
786
|
+
def force_encoding: (string | Encoding encoding) -> self
|
787
|
+
|
788
|
+
def freeze: () -> self
|
789
|
+
|
790
|
+
# returns the *index*th byte as an integer.
|
791
|
+
#
|
792
|
+
def getbyte: (int index) -> Integer?
|
793
|
+
|
794
|
+
# Returns an array of grapheme clusters in *str*. This is a shorthand for
|
795
|
+
# `str.each_grapheme_cluster.to_a`.
|
796
|
+
#
|
797
|
+
# If a block is given, which is a deprecated form, works the same as
|
798
|
+
# `each_grapheme_cluster`.
|
799
|
+
#
|
800
|
+
def grapheme_clusters: () -> ::Array[::String]
|
279
801
|
|
280
|
-
# Returns a
|
281
|
-
#
|
282
|
-
#
|
802
|
+
# Returns a copy of *str* with *all* occurrences of *pattern* substituted for
|
803
|
+
# the second argument. The *pattern* is typically a Regexp; if given as a
|
804
|
+
# String, any regular expression metacharacters it contains will be interpreted
|
805
|
+
# literally, e.g. `\d` will match a backslash followed by 'd', instead of a
|
806
|
+
# digit.
|
807
|
+
#
|
808
|
+
# If `replacement` is a String it will be substituted for the matched text. It
|
809
|
+
# may contain back-references to the pattern's capture groups of the form `\d`,
|
810
|
+
# where *d* is a group number, or `\k<n>`, where *n* is a group name. Similarly,
|
811
|
+
# `\&`, `\'`, `\``, and `+` correspond to special variables, `$&`, `$'`, `$``,
|
812
|
+
# and `$+`, respectively. (See regexp.rdoc for details.) `\0` is the same as
|
813
|
+
# `\&`. `\\\` is interpreted as an escape, i.e., a single backslash. Note that,
|
814
|
+
# within `replacement` the special match variables, such as `$&`, will not refer
|
815
|
+
# to the current match.
|
816
|
+
#
|
817
|
+
# If the second argument is a Hash, and the matched text is one of its keys, the
|
818
|
+
# corresponding value is the replacement string.
|
819
|
+
#
|
820
|
+
# In the block form, the current match string is passed in as a parameter, and
|
821
|
+
# variables such as `$1`, `$2`, `$``, `$&`, and `$'` will be set appropriately.
|
822
|
+
# (See regexp.rdoc for details.) The value returned by the block will be
|
823
|
+
# substituted for the match on each call.
|
824
|
+
#
|
825
|
+
# When neither a block nor a second argument is supplied, an Enumerator is
|
826
|
+
# returned.
|
827
|
+
#
|
828
|
+
# "hello".gsub(/[aeiou]/, '*') #=> "h*ll*"
|
829
|
+
# "hello".gsub(/([aeiou])/, '<\1>') #=> "h<e>ll<o>"
|
830
|
+
# "hello".gsub(/./) {|s| s.ord.to_s + ' '} #=> "104 101 108 108 111 "
|
831
|
+
# "hello".gsub(/(?<foo>[aeiou])/, '{\k<foo>}') #=> "h{e}ll{o}"
|
832
|
+
# 'hello'.gsub(/[eo]/, 'e' => 3, 'o' => '*') #=> "h3ll*"
|
833
|
+
#
|
834
|
+
# Note that a string literal consumes backslashes. (See syntax/literals.rdoc for
|
835
|
+
# details on string literals.) Back-references are typically preceded by an
|
836
|
+
# additional backslash. For example, if you want to write a back-reference `\&`
|
837
|
+
# in `replacement` with a double-quoted string literal, you need to write:
|
838
|
+
# `"..\\\\&.."`. If you want to write a non-back-reference string `\&` in
|
839
|
+
# `replacement`, you need first to escape the backslash to prevent this method
|
840
|
+
# from interpreting it as a back-reference, and then you need to escape the
|
841
|
+
# backslashes again to prevent a string literal from consuming them:
|
842
|
+
# `"..\\\\\\\\&.."`. You may want to use the block form to avoid a lot of
|
843
|
+
# backslashes.
|
844
|
+
#
|
845
|
+
def gsub: (Regexp | string pattern, string replacement) -> String
|
846
|
+
| (Regexp | string pattern, Hash[String, String] hash) -> String
|
847
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> String
|
848
|
+
| (Regexp | string pattern) -> ::Enumerator[String, self]
|
849
|
+
|
850
|
+
# Performs the substitutions of String#gsub in place, returning *str*, or `nil`
|
851
|
+
# if no substitutions were performed. If no block and no *replacement* is
|
852
|
+
# given, an enumerator is returned instead.
|
853
|
+
#
|
854
|
+
def gsub!: (Regexp | string pattern, string replacement) -> String?
|
855
|
+
| (Regexp | string pattern, Hash[String, String] hash) -> String?
|
856
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> String?
|
857
|
+
| (Regexp | string pattern) -> ::Enumerator[String, self]
|
858
|
+
|
859
|
+
# Returns a hash based on the string's length, content and encoding.
|
860
|
+
#
|
861
|
+
# See also Object#hash.
|
862
|
+
#
|
283
863
|
def hash: () -> Integer
|
284
864
|
|
285
|
-
# Treats leading characters from *str* as a string of hexadecimal digits
|
286
|
-
#
|
287
|
-
#
|
288
|
-
#
|
289
|
-
#
|
290
|
-
#
|
291
|
-
#
|
292
|
-
#
|
293
|
-
#
|
294
|
-
# ```
|
865
|
+
# Treats leading characters from *str* as a string of hexadecimal digits (with
|
866
|
+
# an optional sign and an optional `0x`) and returns the corresponding number.
|
867
|
+
# Zero is returned on error.
|
868
|
+
#
|
869
|
+
# "0x0a".hex #=> 10
|
870
|
+
# "-1234".hex #=> -4660
|
871
|
+
# "0".hex #=> 0
|
872
|
+
# "wombat".hex #=> 0
|
873
|
+
#
|
295
874
|
def hex: () -> Integer
|
296
875
|
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
def
|
304
|
-
|
305
|
-
# Returns
|
306
|
-
#
|
307
|
-
#
|
308
|
-
#
|
309
|
-
#
|
310
|
-
#
|
311
|
-
#
|
312
|
-
#
|
876
|
+
# Returns `true` if *str* contains the given string or character.
|
877
|
+
#
|
878
|
+
# "hello".include? "lo" #=> true
|
879
|
+
# "hello".include? "ol" #=> false
|
880
|
+
# "hello".include? ?h #=> true
|
881
|
+
#
|
882
|
+
def include?: (string other_str) -> bool
|
883
|
+
|
884
|
+
# Returns the index of the first occurrence of the given *substring* or pattern
|
885
|
+
# (*regexp*) in *str*. Returns `nil` if not found. If the second parameter is
|
886
|
+
# present, it specifies the position in the string to begin the search.
|
887
|
+
#
|
888
|
+
# "hello".index('e') #=> 1
|
889
|
+
# "hello".index('lo') #=> 3
|
890
|
+
# "hello".index('a') #=> nil
|
891
|
+
# "hello".index(?e) #=> 1
|
892
|
+
# "hello".index(/[aeiou]/, -3) #=> 4
|
893
|
+
#
|
894
|
+
def index: (Regexp | string substr_or_regexp, ?int offset) -> Integer?
|
895
|
+
|
896
|
+
# Inserts *other_str* before the character at the given *index*, modifying
|
897
|
+
# *str*. Negative indices count from the end of the string, and insert *after*
|
898
|
+
# the given character. The intent is insert *aString* so that it starts at the
|
899
|
+
# given *index*.
|
900
|
+
#
|
901
|
+
# "abcd".insert(0, 'X') #=> "Xabcd"
|
902
|
+
# "abcd".insert(3, 'X') #=> "abcXd"
|
903
|
+
# "abcd".insert(4, 'X') #=> "abcdX"
|
904
|
+
# "abcd".insert(-3, 'X') #=> "abXcd"
|
905
|
+
# "abcd".insert(-1, 'X') #=> "abcdX"
|
906
|
+
#
|
907
|
+
def insert: (int index, string other_str) -> String
|
908
|
+
|
909
|
+
# Returns a printable version of *str*, surrounded by quote marks, with special
|
910
|
+
# characters escaped.
|
911
|
+
#
|
912
|
+
# str = "hello"
|
913
|
+
# str[3] = "\b"
|
914
|
+
# str.inspect #=> "\"hel\\bo\""
|
915
|
+
#
|
313
916
|
def inspect: () -> String
|
314
917
|
|
315
|
-
# Returns the
|
316
|
-
#
|
317
|
-
#
|
318
|
-
#
|
319
|
-
#
|
320
|
-
#
|
321
|
-
#
|
322
|
-
#
|
323
|
-
#
|
324
|
-
#
|
325
|
-
#
|
326
|
-
#
|
327
|
-
#
|
328
|
-
#
|
329
|
-
# ```ruby
|
330
|
-
# 'cat and dog'.to_sym #=> :"cat and dog"
|
331
|
-
# ```
|
918
|
+
# Returns the Symbol corresponding to *str*, creating the symbol if it did not
|
919
|
+
# previously exist. See Symbol#id2name.
|
920
|
+
#
|
921
|
+
# "Koala".intern #=> :Koala
|
922
|
+
# s = 'cat'.to_sym #=> :cat
|
923
|
+
# s == :cat #=> true
|
924
|
+
# s = '@cat'.to_sym #=> :@cat
|
925
|
+
# s == :@cat #=> true
|
926
|
+
#
|
927
|
+
# This can also be used to create symbols that cannot be represented using the
|
928
|
+
# `:xxx` notation.
|
929
|
+
#
|
930
|
+
# 'cat and dog'.to_sym #=> :"cat and dog"
|
931
|
+
#
|
332
932
|
def intern: () -> Symbol
|
333
933
|
|
334
|
-
# Returns the character length of *str
|
934
|
+
# Returns the character length of *str*.
|
935
|
+
#
|
335
936
|
def length: () -> Integer
|
336
937
|
|
337
|
-
|
338
|
-
|
339
|
-
|
938
|
+
# Returns an array of lines in *str* split using the supplied record separator
|
939
|
+
# (`$/` by default). This is a shorthand for `str.each_line(separator,
|
940
|
+
# getline_args).to_a`.
|
941
|
+
#
|
942
|
+
# If `chomp` is `true`, `separator` will be removed from the end of each line.
|
943
|
+
#
|
944
|
+
# "hello\nworld\n".lines #=> ["hello\n", "world\n"]
|
945
|
+
# "hello world".lines(' ') #=> ["hello ", " ", "world"]
|
946
|
+
# "hello\nworld\n".lines(chomp: true) #=> ["hello", "world"]
|
947
|
+
#
|
948
|
+
# If a block is given, which is a deprecated form, works the same as
|
949
|
+
# `each_line`.
|
950
|
+
#
|
951
|
+
def lines: (?string separator, ?chomp: bool) -> Array[String]
|
952
|
+
|
953
|
+
# If *integer* is greater than the length of *str*, returns a new String of
|
954
|
+
# length *integer* with *str* left justified and padded with *padstr*;
|
955
|
+
# otherwise, returns *str*.
|
956
|
+
#
|
957
|
+
# "hello".ljust(4) #=> "hello"
|
958
|
+
# "hello".ljust(20) #=> "hello "
|
959
|
+
# "hello".ljust(20, '1234') #=> "hello123412341234123"
|
960
|
+
#
|
961
|
+
def ljust: (int integer, ?string padstr) -> String
|
340
962
|
|
341
963
|
# Returns a copy of the receiver with leading whitespace removed. See also
|
342
|
-
#
|
343
|
-
#
|
344
|
-
#
|
345
|
-
#
|
346
|
-
#
|
347
|
-
#
|
348
|
-
#
|
349
|
-
# " hello ".lstrip #=> "hello "
|
350
|
-
# "hello".lstrip #=> "hello"
|
351
|
-
# ```
|
964
|
+
# String#rstrip and String#strip.
|
965
|
+
#
|
966
|
+
# Refer to String#strip for the definition of whitespace.
|
967
|
+
#
|
968
|
+
# " hello ".lstrip #=> "hello "
|
969
|
+
# "hello".lstrip #=> "hello"
|
970
|
+
#
|
352
971
|
def lstrip: () -> String
|
353
972
|
|
354
|
-
# Removes leading whitespace from the receiver. Returns the altered
|
355
|
-
#
|
356
|
-
#
|
357
|
-
#
|
358
|
-
#
|
359
|
-
#
|
360
|
-
#
|
361
|
-
#
|
362
|
-
#
|
363
|
-
|
364
|
-
|
365
|
-
#
|
366
|
-
#
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
#
|
376
|
-
#
|
377
|
-
#
|
378
|
-
#
|
379
|
-
#
|
380
|
-
#
|
381
|
-
#
|
382
|
-
#
|
973
|
+
# Removes leading whitespace from the receiver. Returns the altered receiver, or
|
974
|
+
# `nil` if no change was made. See also String#rstrip! and String#strip!.
|
975
|
+
#
|
976
|
+
# Refer to String#strip for the definition of whitespace.
|
977
|
+
#
|
978
|
+
# " hello ".lstrip! #=> "hello "
|
979
|
+
# "hello ".lstrip! #=> nil
|
980
|
+
# "hello".lstrip! #=> nil
|
981
|
+
#
|
982
|
+
def lstrip!: () -> self?
|
983
|
+
|
984
|
+
# Converts *pattern* to a Regexp (if it isn't already one), then invokes its
|
985
|
+
# `match` method on the receiver. If the second parameter is present, it
|
986
|
+
# specifies the position in the string to begin the search.
|
987
|
+
#
|
988
|
+
# 'hello'.match('(.)\1') #=> #<MatchData "ll" 1:"l">
|
989
|
+
# 'hello'.match('(.)\1')[0] #=> "ll"
|
990
|
+
# 'hello'.match(/(.)\1/)[0] #=> "ll"
|
991
|
+
# 'hello'.match(/(.)\1/, 3) #=> nil
|
992
|
+
# 'hello'.match('xx') #=> nil
|
993
|
+
#
|
994
|
+
# If a block is given, invokes the block with MatchData if match succeeds, so
|
995
|
+
# that you can write
|
996
|
+
#
|
997
|
+
# str.match(pat) {|m| block }
|
998
|
+
#
|
999
|
+
# instead of
|
1000
|
+
#
|
1001
|
+
# if m = str.match(pat)
|
1002
|
+
# # ...
|
1003
|
+
# end
|
1004
|
+
#
|
1005
|
+
# The return value in this case is the value from block execution.
|
1006
|
+
#
|
1007
|
+
def match: (Regexp | string pattern, ?int pos) -> MatchData?
|
1008
|
+
|
1009
|
+
# Converts *pattern* to a `Regexp` (if it isn't already one), then returns a
|
1010
|
+
# `true` or `false` indicates whether the regexp is matched *str* or not without
|
1011
|
+
# updating `$~` and other related variables. If the second parameter is
|
1012
|
+
# present, it specifies the position in the string to begin the search.
|
1013
|
+
#
|
1014
|
+
# "Ruby".match?(/R.../) #=> true
|
1015
|
+
# "Ruby".match?(/R.../, 1) #=> false
|
1016
|
+
# "Ruby".match?(/P.../) #=> false
|
1017
|
+
# $& #=> nil
|
1018
|
+
#
|
1019
|
+
def match?: (Regexp | string pattern, ?int pos) -> bool
|
1020
|
+
|
1021
|
+
# Returns the successor to *str*. The successor is calculated by incrementing
|
1022
|
+
# characters starting from the rightmost alphanumeric (or the rightmost
|
1023
|
+
# character if there are no alphanumerics) in the string. Incrementing a digit
|
1024
|
+
# always results in another digit, and incrementing a letter results in another
|
1025
|
+
# letter of the same case. Incrementing nonalphanumerics uses the underlying
|
1026
|
+
# character set's collating sequence.
|
1027
|
+
#
|
1028
|
+
# If the increment generates a ``carry,'' the character to the left of it is
|
383
1029
|
# incremented. This process repeats until there is no carry, adding an
|
384
1030
|
# additional character if necessary.
|
385
|
-
#
|
386
|
-
#
|
387
|
-
#
|
388
|
-
#
|
389
|
-
#
|
390
|
-
#
|
391
|
-
#
|
392
|
-
#
|
393
|
-
# ```
|
1031
|
+
#
|
1032
|
+
# "abcd".succ #=> "abce"
|
1033
|
+
# "THX1138".succ #=> "THX1139"
|
1034
|
+
# "<<koala>>".succ #=> "<<koalb>>"
|
1035
|
+
# "1999zzz".succ #=> "2000aaa"
|
1036
|
+
# "ZZZ9999".succ #=> "AAAA0000"
|
1037
|
+
# "***".succ #=> "**+"
|
1038
|
+
#
|
394
1039
|
def next: () -> String
|
395
1040
|
|
396
|
-
# Equivalent to
|
397
|
-
|
1041
|
+
# Equivalent to String#succ, but modifies the receiver in place.
|
1042
|
+
#
|
1043
|
+
def next!: () -> self
|
398
1044
|
|
399
1045
|
# Treats leading characters of *str* as a string of octal digits (with an
|
400
|
-
# optional sign) and returns the corresponding number.
|
1046
|
+
# optional sign) and returns the corresponding number. Returns 0 if the
|
401
1047
|
# conversion fails.
|
402
|
-
#
|
403
|
-
#
|
404
|
-
#
|
405
|
-
#
|
406
|
-
#
|
407
|
-
#
|
408
|
-
#
|
409
|
-
#
|
410
|
-
# If `str` starts with `0`, radix indicators are honored. See
|
411
|
-
# Kernel\#Integer.
|
1048
|
+
#
|
1049
|
+
# "123".oct #=> 83
|
1050
|
+
# "-377".oct #=> -255
|
1051
|
+
# "bad".oct #=> 0
|
1052
|
+
# "0377bad".oct #=> 255
|
1053
|
+
#
|
1054
|
+
# If `str` starts with `0`, radix indicators are honored. See Kernel#Integer.
|
1055
|
+
#
|
412
1056
|
def oct: () -> Integer
|
413
1057
|
|
414
|
-
# Returns the
|
415
|
-
#
|
416
|
-
#
|
417
|
-
#
|
418
|
-
# ```
|
1058
|
+
# Returns the Integer ordinal of a one-character string.
|
1059
|
+
#
|
1060
|
+
# "a".ord #=> 97
|
1061
|
+
#
|
419
1062
|
def ord: () -> Integer
|
420
1063
|
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
1064
|
+
# Searches *sep* or pattern (*regexp*) in the string and returns the part before
|
1065
|
+
# it, the match, and the part after it. If it is not found, returns two empty
|
1066
|
+
# strings and *str*.
|
1067
|
+
#
|
1068
|
+
# "hello".partition("l") #=> ["he", "l", "lo"]
|
1069
|
+
# "hello".partition("x") #=> ["hello", "", ""]
|
1070
|
+
# "hello".partition(/.l/) #=> ["h", "el", "lo"]
|
1071
|
+
#
|
1072
|
+
def partition: (Regexp | string sep_or_regexp) -> [ String, String, String ]
|
1073
|
+
|
1074
|
+
# Prepend---Prepend the given strings to *str*.
|
1075
|
+
#
|
1076
|
+
# a = "!"
|
1077
|
+
# a.prepend("hello ", "world") #=> "hello world!"
|
1078
|
+
# a #=> "hello world!"
|
1079
|
+
#
|
1080
|
+
# See also String#concat.
|
1081
|
+
#
|
1082
|
+
def prepend: (*string other_strs) -> String
|
1083
|
+
|
1084
|
+
# Replaces the contents of *str* with the corresponding values in *other_str*.
|
1085
|
+
#
|
1086
|
+
# s = "hello" #=> "hello"
|
1087
|
+
# s.replace "world" #=> "world"
|
1088
|
+
#
|
1089
|
+
def replace: (string other_str) -> String
|
426
1090
|
|
427
1091
|
# Returns a new string with the characters from *str* in reverse order.
|
428
|
-
#
|
429
|
-
#
|
430
|
-
#
|
431
|
-
# ```
|
1092
|
+
#
|
1093
|
+
# "stressed".reverse #=> "desserts"
|
1094
|
+
#
|
432
1095
|
def reverse: () -> String
|
433
1096
|
|
434
|
-
|
435
|
-
|
436
|
-
def
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
#
|
441
|
-
#
|
442
|
-
#
|
443
|
-
#
|
444
|
-
#
|
445
|
-
#
|
446
|
-
#
|
447
|
-
#
|
448
|
-
#
|
449
|
-
|
450
|
-
|
1097
|
+
# Reverses *str* in place.
|
1098
|
+
#
|
1099
|
+
def reverse!: () -> self
|
1100
|
+
|
1101
|
+
# Returns the index of the last occurrence of the given *substring* or pattern
|
1102
|
+
# (*regexp*) in *str*. Returns `nil` if not found. If the second parameter is
|
1103
|
+
# present, it specifies the position in the string to end the
|
1104
|
+
# search---characters beyond this point will not be considered.
|
1105
|
+
#
|
1106
|
+
# "hello".rindex('e') #=> 1
|
1107
|
+
# "hello".rindex('l') #=> 3
|
1108
|
+
# "hello".rindex('a') #=> nil
|
1109
|
+
# "hello".rindex(?e) #=> 1
|
1110
|
+
# "hello".rindex(/[aeiou]/, -2) #=> 1
|
1111
|
+
#
|
1112
|
+
def rindex: (string | Regexp substr_or_regexp, ?int pos) -> Integer?
|
1113
|
+
|
1114
|
+
# If *integer* is greater than the length of *str*, returns a new String of
|
1115
|
+
# length *integer* with *str* right justified and padded with *padstr*;
|
1116
|
+
# otherwise, returns *str*.
|
1117
|
+
#
|
1118
|
+
# "hello".rjust(4) #=> "hello"
|
1119
|
+
# "hello".rjust(20) #=> " hello"
|
1120
|
+
# "hello".rjust(20, '1234') #=> "123412341234123hello"
|
1121
|
+
#
|
1122
|
+
def rjust: (int integer, ?string padstr) -> String
|
1123
|
+
|
1124
|
+
# Searches *sep* or pattern (*regexp*) in the string from the end of the string,
|
1125
|
+
# and returns the part before it, the match, and the part after it. If it is not
|
1126
|
+
# found, returns two empty strings and *str*.
|
1127
|
+
#
|
1128
|
+
# "hello".rpartition("l") #=> ["hel", "l", "o"]
|
1129
|
+
# "hello".rpartition("x") #=> ["", "", "hello"]
|
1130
|
+
# "hello".rpartition(/.l/) #=> ["he", "ll", "o"]
|
1131
|
+
#
|
1132
|
+
def rpartition: (string | Regexp sep_or_regexp) -> [ String, String, String ]
|
1133
|
+
|
1134
|
+
# Returns a copy of the receiver with trailing whitespace removed. See also
|
1135
|
+
# String#lstrip and String#strip.
|
1136
|
+
#
|
1137
|
+
# Refer to String#strip for the definition of whitespace.
|
1138
|
+
#
|
1139
|
+
# " hello ".rstrip #=> " hello"
|
1140
|
+
# "hello".rstrip #=> "hello"
|
1141
|
+
#
|
451
1142
|
def rstrip: () -> String
|
452
1143
|
|
453
|
-
# Removes trailing whitespace from the receiver. Returns the altered
|
454
|
-
#
|
455
|
-
#
|
456
|
-
#
|
457
|
-
#
|
458
|
-
#
|
459
|
-
#
|
460
|
-
#
|
461
|
-
#
|
462
|
-
|
463
|
-
|
464
|
-
#
|
465
|
-
#
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
#
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
#
|
498
|
-
#
|
499
|
-
#
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
#
|
504
|
-
#
|
505
|
-
#
|
506
|
-
#
|
507
|
-
#
|
508
|
-
#
|
509
|
-
#
|
1144
|
+
# Removes trailing whitespace from the receiver. Returns the altered receiver,
|
1145
|
+
# or `nil` if no change was made. See also String#lstrip! and String#strip!.
|
1146
|
+
#
|
1147
|
+
# Refer to String#strip for the definition of whitespace.
|
1148
|
+
#
|
1149
|
+
# " hello ".rstrip! #=> " hello"
|
1150
|
+
# " hello".rstrip! #=> nil
|
1151
|
+
# "hello".rstrip! #=> nil
|
1152
|
+
#
|
1153
|
+
def rstrip!: () -> self?
|
1154
|
+
|
1155
|
+
# Both forms iterate through *str*, matching the pattern (which may be a Regexp
|
1156
|
+
# or a String). For each match, a result is generated and either added to the
|
1157
|
+
# result array or passed to the block. If the pattern contains no groups, each
|
1158
|
+
# individual result consists of the matched string, `$&`. If the pattern
|
1159
|
+
# contains groups, each individual result is itself an array containing one
|
1160
|
+
# entry per group.
|
1161
|
+
#
|
1162
|
+
# a = "cruel world"
|
1163
|
+
# a.scan(/\w+/) #=> ["cruel", "world"]
|
1164
|
+
# a.scan(/.../) #=> ["cru", "el ", "wor"]
|
1165
|
+
# a.scan(/(...)/) #=> [["cru"], ["el "], ["wor"]]
|
1166
|
+
# a.scan(/(..)(..)/) #=> [["cr", "ue"], ["l ", "wo"]]
|
1167
|
+
#
|
1168
|
+
# And the block form:
|
1169
|
+
#
|
1170
|
+
# a.scan(/\w+/) {|w| print "<<#{w}>> " }
|
1171
|
+
# print "\n"
|
1172
|
+
# a.scan(/(.)(.)/) {|x,y| print y, x }
|
1173
|
+
# print "\n"
|
1174
|
+
#
|
1175
|
+
# *produces:*
|
1176
|
+
#
|
1177
|
+
# <<cruel>> <<world>>
|
1178
|
+
# rceu lowlr
|
1179
|
+
#
|
1180
|
+
def scan: (Regexp | string pattern) -> Array[String | Array[String]]
|
1181
|
+
| (Regexp | string pattern) { (String | Array[String]) -> void } -> self
|
1182
|
+
|
1183
|
+
# If the string is invalid byte sequence then replace invalid bytes with given
|
1184
|
+
# replacement character, else returns self. If block is given, replace invalid
|
1185
|
+
# bytes with returned value of the block.
|
1186
|
+
#
|
1187
|
+
# "abc\u3042\x81".scrub #=> "abc\u3042\uFFFD"
|
1188
|
+
# "abc\u3042\x81".scrub("*") #=> "abc\u3042*"
|
1189
|
+
# "abc\u3042\xE3\x80".scrub{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>"
|
1190
|
+
#
|
1191
|
+
def scrub: (?string repl) -> String
|
1192
|
+
| () { (String bytes) -> string } -> String
|
1193
|
+
|
1194
|
+
# If the string is invalid byte sequence then replace invalid bytes with given
|
1195
|
+
# replacement character, else returns self. If block is given, replace invalid
|
1196
|
+
# bytes with returned value of the block.
|
1197
|
+
#
|
1198
|
+
# "abc\u3042\x81".scrub! #=> "abc\u3042\uFFFD"
|
1199
|
+
# "abc\u3042\x81".scrub!("*") #=> "abc\u3042*"
|
1200
|
+
# "abc\u3042\xE3\x80".scrub!{|bytes| '<'+bytes.unpack('H*')[0]+'>' } #=> "abc\u3042<e380>"
|
1201
|
+
#
|
1202
|
+
def scrub!: (?string repl) -> self
|
1203
|
+
| () { (String bytes) -> string } -> self
|
1204
|
+
|
1205
|
+
# modifies the *index*th byte as *integer*.
|
1206
|
+
#
|
1207
|
+
def setbyte: (int index, int integer) -> int
|
1208
|
+
|
1209
|
+
# Returns the character length of *str*.
|
1210
|
+
#
|
1211
|
+
alias size length
|
1212
|
+
|
1213
|
+
# Element Reference --- If passed a single `index`, returns a substring of one
|
1214
|
+
# character at that index. If passed a `start` index and a `length`, returns a
|
1215
|
+
# substring containing `length` characters starting at the `start` index. If
|
1216
|
+
# passed a `range`, its beginning and end are interpreted as offsets delimiting
|
1217
|
+
# the substring to be returned.
|
1218
|
+
#
|
1219
|
+
# In these three cases, if an index is negative, it is counted from the end of
|
1220
|
+
# the string. For the `start` and `range` cases the starting index is just
|
1221
|
+
# before a character and an index matching the string's size. Additionally, an
|
1222
|
+
# empty string is returned when the starting index for a character range is at
|
1223
|
+
# the end of the string.
|
1224
|
+
#
|
1225
|
+
# Returns `nil` if the initial index falls outside the string or the length is
|
1226
|
+
# negative.
|
1227
|
+
#
|
1228
|
+
# If a `Regexp` is supplied, the matching portion of the string is returned. If
|
1229
|
+
# a `capture` follows the regular expression, which may be a capture group index
|
1230
|
+
# or name, follows the regular expression that component of the MatchData is
|
1231
|
+
# returned instead.
|
1232
|
+
#
|
1233
|
+
# If a `match_str` is given, that string is returned if it occurs in the string.
|
1234
|
+
#
|
1235
|
+
# Returns `nil` if the regular expression does not match or the match string
|
1236
|
+
# cannot be found.
|
1237
|
+
#
|
1238
|
+
# a = "hello there"
|
1239
|
+
#
|
1240
|
+
# a[1] #=> "e"
|
1241
|
+
# a[2, 3] #=> "llo"
|
1242
|
+
# a[2..3] #=> "ll"
|
1243
|
+
#
|
1244
|
+
# a[-3, 2] #=> "er"
|
1245
|
+
# a[7..-2] #=> "her"
|
1246
|
+
# a[-4..-2] #=> "her"
|
1247
|
+
# a[-2..-4] #=> ""
|
1248
|
+
#
|
1249
|
+
# a[11, 0] #=> ""
|
1250
|
+
# a[11] #=> nil
|
1251
|
+
# a[12, 0] #=> nil
|
1252
|
+
# a[12..-1] #=> nil
|
1253
|
+
#
|
1254
|
+
# a[/[aeiou](.)\1/] #=> "ell"
|
1255
|
+
# a[/[aeiou](.)\1/, 0] #=> "ell"
|
1256
|
+
# a[/[aeiou](.)\1/, 1] #=> "l"
|
1257
|
+
# a[/[aeiou](.)\1/, 2] #=> nil
|
1258
|
+
#
|
1259
|
+
# a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "non_vowel"] #=> "l"
|
1260
|
+
# a[/(?<vowel>[aeiou])(?<non_vowel>[^aeiou])/, "vowel"] #=> "e"
|
1261
|
+
#
|
1262
|
+
# a["lo"] #=> "lo"
|
1263
|
+
# a["bye"] #=> nil
|
1264
|
+
#
|
1265
|
+
alias slice []
|
1266
|
+
|
1267
|
+
# Deletes the specified portion from *str*, and returns the portion deleted.
|
1268
|
+
#
|
1269
|
+
# string = "this is a string"
|
1270
|
+
# string.slice!(2) #=> "i"
|
1271
|
+
# string.slice!(3..6) #=> " is "
|
1272
|
+
# string.slice!(/s.*t/) #=> "sa st"
|
1273
|
+
# string.slice!("r") #=> "r"
|
1274
|
+
# string #=> "thing"
|
1275
|
+
#
|
1276
|
+
def slice!: (int integer, ?int integer) -> String?
|
1277
|
+
| (Range[Integer] | Range[Integer?] range) -> String?
|
1278
|
+
| (Regexp regexp, ?int | String capture) -> String?
|
1279
|
+
| (String other_str) -> String?
|
1280
|
+
|
1281
|
+
# Divides *str* into substrings based on a delimiter, returning an array of
|
1282
|
+
# these substrings.
|
1283
|
+
#
|
1284
|
+
# If *pattern* is a String, then its contents are used as the delimiter when
|
1285
|
+
# splitting *str*. If *pattern* is a single space, *str* is split on whitespace,
|
1286
|
+
# with leading and trailing whitespace and runs of contiguous whitespace
|
1287
|
+
# characters ignored.
|
1288
|
+
#
|
1289
|
+
# If *pattern* is a Regexp, *str* is divided where the pattern matches. Whenever
|
1290
|
+
# the pattern matches a zero-length string, *str* is split into individual
|
1291
|
+
# characters. If *pattern* contains groups, the respective matches will be
|
1292
|
+
# returned in the array as well.
|
1293
|
+
#
|
1294
|
+
# If *pattern* is `nil`, the value of `$;` is used. If `$;` is `nil` (which is
|
1295
|
+
# the default), *str* is split on whitespace as if ' ' were specified.
|
1296
|
+
#
|
1297
|
+
# If the *limit* parameter is omitted, trailing null fields are suppressed. If
|
1298
|
+
# *limit* is a positive number, at most that number of split substrings will be
|
1299
|
+
# returned (captured groups will be returned as well, but are not counted
|
1300
|
+
# towards the limit). If *limit* is `1`, the entire string is returned as the
|
1301
|
+
# only entry in an array. If negative, there is no limit to the number of fields
|
1302
|
+
# returned, and trailing null fields are not suppressed.
|
1303
|
+
#
|
1304
|
+
# When the input `str` is empty an empty Array is returned as the string is
|
1305
|
+
# considered to have no fields to split.
|
1306
|
+
#
|
1307
|
+
# " now's the time ".split #=> ["now's", "the", "time"]
|
1308
|
+
# " now's the time ".split(' ') #=> ["now's", "the", "time"]
|
1309
|
+
# " now's the time".split(/ /) #=> ["", "now's", "", "the", "time"]
|
1310
|
+
# "1, 2.34,56, 7".split(%r{,\s*}) #=> ["1", "2.34", "56", "7"]
|
1311
|
+
# "hello".split(//) #=> ["h", "e", "l", "l", "o"]
|
1312
|
+
# "hello".split(//, 3) #=> ["h", "e", "llo"]
|
1313
|
+
# "hi mom".split(%r{\s*}) #=> ["h", "i", "m", "o", "m"]
|
1314
|
+
#
|
1315
|
+
# "mellow yellow".split("ello") #=> ["m", "w y", "w"]
|
1316
|
+
# "1,2,,3,4,,".split(',') #=> ["1", "2", "", "3", "4"]
|
1317
|
+
# "1,2,,3,4,,".split(',', 4) #=> ["1", "2", "", "3,4,,"]
|
1318
|
+
# "1,2,,3,4,,".split(',', -4) #=> ["1", "2", "", "3", "4", "", ""]
|
1319
|
+
#
|
1320
|
+
# "1:2:3".split(/(:)()()/, 2) #=> ["1", ":", "", "", "2:3"]
|
1321
|
+
#
|
1322
|
+
# "".split(',', -1) #=> []
|
1323
|
+
#
|
1324
|
+
# If a block is given, invoke the block with each split substring.
|
1325
|
+
#
|
1326
|
+
def split: (?Regexp | string pattern, ?int limit) -> Array[String]
|
1327
|
+
| (?Regexp | string pattern, ?int limit) { (String) -> void } -> self
|
1328
|
+
|
1329
|
+
# Builds a set of characters from the *other_str* parameter(s) using the
|
1330
|
+
# procedure described for String#count. Returns a new string where runs of the
|
1331
|
+
# same character that occur in this set are replaced by a single character. If
|
1332
|
+
# no arguments are given, all runs of identical characters are replaced by a
|
1333
|
+
# single character.
|
1334
|
+
#
|
1335
|
+
# "yellow moon".squeeze #=> "yelow mon"
|
1336
|
+
# " now is the".squeeze(" ") #=> " now is the"
|
1337
|
+
# "putters shoot balls".squeeze("m-z") #=> "puters shot balls"
|
1338
|
+
#
|
1339
|
+
def squeeze: (*string other_str) -> String
|
1340
|
+
|
1341
|
+
# Squeezes *str* in place, returning either *str*, or `nil` if no changes were
|
1342
|
+
# made.
|
1343
|
+
#
|
1344
|
+
def squeeze!: (*string other_str) -> self?
|
1345
|
+
|
1346
|
+
# Returns true if `str` starts with one of the `prefixes` given. Each of the
|
1347
|
+
# `prefixes` should be a String or a Regexp.
|
1348
|
+
#
|
1349
|
+
# "hello".start_with?("hell") #=> true
|
1350
|
+
# "hello".start_with?(/H/i) #=> true
|
1351
|
+
#
|
1352
|
+
# # returns true if one of the prefixes matches.
|
1353
|
+
# "hello".start_with?("heaven", "hell") #=> true
|
1354
|
+
# "hello".start_with?("heaven", "paradise") #=> false
|
1355
|
+
#
|
1356
|
+
def start_with?: (*string prefixes) -> bool
|
1357
|
+
|
1358
|
+
# Returns a copy of the receiver with leading and trailing whitespace removed.
|
1359
|
+
#
|
1360
|
+
# Whitespace is defined as any of the following characters: null, horizontal
|
1361
|
+
# tab, line feed, vertical tab, form feed, carriage return, space.
|
1362
|
+
#
|
1363
|
+
# " hello ".strip #=> "hello"
|
1364
|
+
# "\tgoodbye\r\n".strip #=> "goodbye"
|
1365
|
+
# "\x00\t\n\v\f\r ".strip #=> ""
|
1366
|
+
# "hello".strip #=> "hello"
|
1367
|
+
#
|
510
1368
|
def strip: () -> String
|
511
1369
|
|
512
|
-
# Removes leading and trailing whitespace from the receiver. Returns the
|
513
|
-
#
|
514
|
-
#
|
515
|
-
# Refer to
|
516
|
-
#
|
517
|
-
#
|
518
|
-
#
|
519
|
-
#
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
#
|
531
|
-
#
|
532
|
-
#
|
533
|
-
#
|
534
|
-
#
|
535
|
-
#
|
536
|
-
#
|
537
|
-
# If the
|
1370
|
+
# Removes leading and trailing whitespace from the receiver. Returns the altered
|
1371
|
+
# receiver, or `nil` if there was no change.
|
1372
|
+
#
|
1373
|
+
# Refer to String#strip for the definition of whitespace.
|
1374
|
+
#
|
1375
|
+
# " hello ".strip! #=> "hello"
|
1376
|
+
# "hello".strip! #=> nil
|
1377
|
+
#
|
1378
|
+
def strip!: () -> self?
|
1379
|
+
|
1380
|
+
# Returns a copy of `str` with the *first* occurrence of `pattern` replaced by
|
1381
|
+
# the second argument. The `pattern` is typically a Regexp; if given as a
|
1382
|
+
# String, any regular expression metacharacters it contains will be interpreted
|
1383
|
+
# literally, e.g. `\d` will match a backslash followed by 'd', instead of a
|
1384
|
+
# digit.
|
1385
|
+
#
|
1386
|
+
# If `replacement` is a String it will be substituted for the matched text. It
|
1387
|
+
# may contain back-references to the pattern's capture groups of the form `\d`,
|
1388
|
+
# where *d* is a group number, or `\k<n>`, where *n* is a group name. Similarly,
|
1389
|
+
# `\&`, `\'`, `\``, and `+` correspond to special variables, `$&`, `$'`, `$``,
|
1390
|
+
# and `$+`, respectively. (See regexp.rdoc for details.) `\0` is the same as
|
1391
|
+
# `\&`. `\\\` is interpreted as an escape, i.e., a single backslash. Note that,
|
1392
|
+
# within `replacement` the special match variables, such as `$&`, will not refer
|
1393
|
+
# to the current match.
|
1394
|
+
#
|
1395
|
+
# If the second argument is a Hash, and the matched text is one of its keys, the
|
1396
|
+
# corresponding value is the replacement string.
|
1397
|
+
#
|
1398
|
+
# In the block form, the current match string is passed in as a parameter, and
|
1399
|
+
# variables such as `$1`, `$2`, `$``, `$&`, and `$'` will be set appropriately.
|
1400
|
+
# (See regexp.rdoc for details.) The value returned by the block will be
|
1401
|
+
# substituted for the match on each call.
|
1402
|
+
#
|
1403
|
+
# "hello".sub(/[aeiou]/, '*') #=> "h*llo"
|
1404
|
+
# "hello".sub(/([aeiou])/, '<\1>') #=> "h<e>llo"
|
1405
|
+
# "hello".sub(/./) {|s| s.ord.to_s + ' ' } #=> "104 ello"
|
1406
|
+
# "hello".sub(/(?<foo>[aeiou])/, '*\k<foo>*') #=> "h*e*llo"
|
1407
|
+
# 'Is SHELL your preferred shell?'.sub(/[[:upper:]]{2,}/, ENV)
|
1408
|
+
# #=> "Is /bin/bash your preferred shell?"
|
1409
|
+
#
|
1410
|
+
# Note that a string literal consumes backslashes. (See syntax/literals.rdoc for
|
1411
|
+
# details about string literals.) Back-references are typically preceded by an
|
1412
|
+
# additional backslash. For example, if you want to write a back-reference `\&`
|
1413
|
+
# in `replacement` with a double-quoted string literal, you need to write:
|
1414
|
+
# `"..\\\\&.."`. If you want to write a non-back-reference string `\&` in
|
1415
|
+
# `replacement`, you need first to escape the backslash to prevent this method
|
1416
|
+
# from interpreting it as a back-reference, and then you need to escape the
|
1417
|
+
# backslashes again to prevent a string literal from consuming them:
|
1418
|
+
# `"..\\\\\\\\&.."`. You may want to use the block form to avoid a lot of
|
1419
|
+
# backslashes.
|
1420
|
+
#
|
1421
|
+
def sub: (Regexp | string pattern, string | Hash[String, String] replacement) -> String
|
1422
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> String
|
1423
|
+
|
1424
|
+
# Performs the same substitution as String#sub in-place.
|
1425
|
+
#
|
1426
|
+
# Returns `str` if a substitution was performed or `nil` if no substitution was
|
1427
|
+
# performed.
|
1428
|
+
#
|
1429
|
+
def sub!: (Regexp | string pattern, string | Hash[String, String] replacement) -> self?
|
1430
|
+
| (Regexp | string pattern) { (String match) -> _ToS } -> String?
|
1431
|
+
|
1432
|
+
# Returns the successor to *str*. The successor is calculated by incrementing
|
1433
|
+
# characters starting from the rightmost alphanumeric (or the rightmost
|
1434
|
+
# character if there are no alphanumerics) in the string. Incrementing a digit
|
1435
|
+
# always results in another digit, and incrementing a letter results in another
|
1436
|
+
# letter of the same case. Incrementing nonalphanumerics uses the underlying
|
1437
|
+
# character set's collating sequence.
|
1438
|
+
#
|
1439
|
+
# If the increment generates a ``carry,'' the character to the left of it is
|
538
1440
|
# incremented. This process repeats until there is no carry, adding an
|
539
1441
|
# additional character if necessary.
|
540
|
-
#
|
541
|
-
#
|
542
|
-
#
|
543
|
-
#
|
544
|
-
#
|
545
|
-
#
|
546
|
-
#
|
547
|
-
#
|
548
|
-
# ```
|
1442
|
+
#
|
1443
|
+
# "abcd".succ #=> "abce"
|
1444
|
+
# "THX1138".succ #=> "THX1139"
|
1445
|
+
# "<<koala>>".succ #=> "<<koalb>>"
|
1446
|
+
# "1999zzz".succ #=> "2000aaa"
|
1447
|
+
# "ZZZ9999".succ #=> "AAAA0000"
|
1448
|
+
# "***".succ #=> "**+"
|
1449
|
+
#
|
549
1450
|
def succ: () -> String
|
550
1451
|
|
1452
|
+
# Equivalent to String#succ, but modifies the receiver in place.
|
1453
|
+
#
|
551
1454
|
def succ!: () -> String
|
552
1455
|
|
553
|
-
|
554
|
-
|
555
|
-
#
|
556
|
-
#
|
557
|
-
#
|
558
|
-
|
559
|
-
|
560
|
-
#
|
561
|
-
#
|
562
|
-
#
|
563
|
-
#
|
564
|
-
#
|
1456
|
+
# Returns a basic *n*-bit checksum of the characters in *str*, where *n* is the
|
1457
|
+
# optional Integer parameter, defaulting to 16. The result is simply the sum of
|
1458
|
+
# the binary value of each byte in *str* modulo `2**n - 1`. This is not a
|
1459
|
+
# particularly good checksum.
|
1460
|
+
#
|
1461
|
+
def sum: (?int n) -> Integer
|
1462
|
+
|
1463
|
+
# Returns a copy of *str* with uppercase alphabetic characters converted to
|
1464
|
+
# lowercase and lowercase characters converted to uppercase.
|
1465
|
+
#
|
1466
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
1467
|
+
#
|
1468
|
+
# "Hello".swapcase #=> "hELLO"
|
1469
|
+
# "cYbEr_PuNk11".swapcase #=> "CyBeR_pUnK11"
|
1470
|
+
#
|
565
1471
|
def swapcase: () -> String
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
#
|
571
|
-
#
|
572
|
-
|
573
|
-
|
574
|
-
#
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
#
|
581
|
-
#
|
582
|
-
#
|
583
|
-
#
|
584
|
-
#
|
585
|
-
#
|
586
|
-
#
|
587
|
-
#
|
588
|
-
#
|
589
|
-
#
|
590
|
-
#
|
591
|
-
#
|
592
|
-
#
|
1472
|
+
| (:ascii | :lithuanian | :turkic) -> String
|
1473
|
+
| (:lithuanian, :turkic) -> String
|
1474
|
+
| (:turkic, :lithuanian) -> String
|
1475
|
+
|
1476
|
+
# Equivalent to String#swapcase, but modifies the receiver in place, returning
|
1477
|
+
# *str*, or `nil` if no changes were made.
|
1478
|
+
#
|
1479
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
1480
|
+
#
|
1481
|
+
def swapcase!: () -> self?
|
1482
|
+
| (:ascii | :lithuanian | :turkic) -> self?
|
1483
|
+
| (:lithuanian, :turkic) -> self?
|
1484
|
+
| (:turkic, :lithuanian) -> self?
|
1485
|
+
|
1486
|
+
# Returns a complex which denotes the string form. The parser ignores leading
|
1487
|
+
# whitespaces and trailing garbage. Any digit sequences can be separated by an
|
1488
|
+
# underscore. Returns zero for null or garbage string.
|
1489
|
+
#
|
1490
|
+
# '9'.to_c #=> (9+0i)
|
1491
|
+
# '2.5'.to_c #=> (2.5+0i)
|
1492
|
+
# '2.5/1'.to_c #=> ((5/2)+0i)
|
1493
|
+
# '-3/2'.to_c #=> ((-3/2)+0i)
|
1494
|
+
# '-i'.to_c #=> (0-1i)
|
1495
|
+
# '45i'.to_c #=> (0+45i)
|
1496
|
+
# '3-4i'.to_c #=> (3-4i)
|
1497
|
+
# '-4e2-4e-2i'.to_c #=> (-400.0-0.04i)
|
1498
|
+
# '-0.0-0.0i'.to_c #=> (-0.0-0.0i)
|
1499
|
+
# '1/2+3/4i'.to_c #=> ((1/2)+(3/4)*i)
|
1500
|
+
# 'ruby'.to_c #=> (0+0i)
|
1501
|
+
#
|
1502
|
+
# See Kernel.Complex.
|
1503
|
+
#
|
593
1504
|
def to_c: () -> Complex
|
594
1505
|
|
595
|
-
# Returns the result of interpreting leading characters in *str* as a
|
596
|
-
#
|
597
|
-
#
|
598
|
-
#
|
599
|
-
#
|
600
|
-
#
|
601
|
-
#
|
602
|
-
#
|
603
|
-
#
|
604
|
-
# ```
|
1506
|
+
# Returns the result of interpreting leading characters in *str* as a floating
|
1507
|
+
# point number. Extraneous characters past the end of a valid number are
|
1508
|
+
# ignored. If there is not a valid number at the start of *str*, `0.0` is
|
1509
|
+
# returned. This method never raises an exception.
|
1510
|
+
#
|
1511
|
+
# "123.45e1".to_f #=> 1234.5
|
1512
|
+
# "45.67 degrees".to_f #=> 45.67
|
1513
|
+
# "thx1138".to_f #=> 0.0
|
1514
|
+
#
|
605
1515
|
def to_f: () -> Float
|
606
1516
|
|
607
|
-
|
608
|
-
|
609
|
-
#
|
610
|
-
#
|
611
|
-
#
|
612
|
-
#
|
613
|
-
#
|
614
|
-
#
|
615
|
-
#
|
616
|
-
#
|
617
|
-
#
|
618
|
-
#
|
619
|
-
#
|
620
|
-
#
|
621
|
-
#
|
622
|
-
|
623
|
-
|
624
|
-
#
|
625
|
-
#
|
626
|
-
#
|
627
|
-
#
|
628
|
-
#
|
1517
|
+
# Returns the result of interpreting leading characters in *str* as an integer
|
1518
|
+
# base *base* (between 2 and 36). Extraneous characters past the end of a valid
|
1519
|
+
# number are ignored. If there is not a valid number at the start of *str*, `0`
|
1520
|
+
# is returned. This method never raises an exception when *base* is valid.
|
1521
|
+
#
|
1522
|
+
# "12345".to_i #=> 12345
|
1523
|
+
# "99 red balloons".to_i #=> 99
|
1524
|
+
# "0a".to_i #=> 0
|
1525
|
+
# "0a".to_i(16) #=> 10
|
1526
|
+
# "hello".to_i #=> 0
|
1527
|
+
# "1100101".to_i(2) #=> 101
|
1528
|
+
# "1100101".to_i(8) #=> 294977
|
1529
|
+
# "1100101".to_i(10) #=> 1100101
|
1530
|
+
# "1100101".to_i(16) #=> 17826049
|
1531
|
+
#
|
1532
|
+
def to_i: (?int base) -> Integer
|
1533
|
+
|
1534
|
+
# Returns the result of interpreting leading characters in `str` as a rational.
|
1535
|
+
# Leading whitespace and extraneous characters past the end of a valid number
|
1536
|
+
# are ignored. Digit sequences can be separated by an underscore. If there is
|
1537
|
+
# not a valid number at the start of `str`, zero is returned. This method never
|
1538
|
+
# raises an exception.
|
1539
|
+
#
|
1540
|
+
# ' 2 '.to_r #=> (2/1)
|
1541
|
+
# '300/2'.to_r #=> (150/1)
|
1542
|
+
# '-9.2'.to_r #=> (-46/5)
|
1543
|
+
# '-9.2e2'.to_r #=> (-920/1)
|
1544
|
+
# '1_234_567'.to_r #=> (1234567/1)
|
1545
|
+
# '21 June 09'.to_r #=> (21/1)
|
1546
|
+
# '21/06/09'.to_r #=> (7/2)
|
1547
|
+
# 'BWV 1079'.to_r #=> (0/1)
|
1548
|
+
#
|
1549
|
+
# NOTE: "0.3".to_r isn't the same as 0.3.to_r. The former is equivalent to
|
1550
|
+
# "3/10".to_r, but the latter isn't so.
|
1551
|
+
#
|
629
1552
|
# "0.3".to_r == 3/10r #=> true
|
630
1553
|
# 0.3.to_r == 3/10r #=> false
|
631
|
-
#
|
632
|
-
# See also Kernel
|
1554
|
+
#
|
1555
|
+
# See also Kernel#Rational.
|
1556
|
+
#
|
633
1557
|
def to_r: () -> Rational
|
634
1558
|
|
635
|
-
# Returns `self
|
636
|
-
#
|
637
|
-
# If called on a subclass of
|
638
|
-
#
|
1559
|
+
# Returns `self`.
|
1560
|
+
#
|
1561
|
+
# If called on a subclass of String, converts the receiver to a String object.
|
1562
|
+
#
|
639
1563
|
def to_s: () -> String
|
640
1564
|
|
641
|
-
# Returns `self
|
642
|
-
#
|
643
|
-
# If called on a subclass of
|
644
|
-
#
|
1565
|
+
# Returns `self`.
|
1566
|
+
#
|
1567
|
+
# If called on a subclass of String, converts the receiver to a String object.
|
1568
|
+
#
|
645
1569
|
def to_str: () -> String
|
646
1570
|
|
647
|
-
# Returns the
|
648
|
-
#
|
649
|
-
#
|
650
|
-
#
|
651
|
-
#
|
652
|
-
#
|
653
|
-
#
|
654
|
-
#
|
655
|
-
#
|
656
|
-
#
|
657
|
-
#
|
658
|
-
#
|
659
|
-
#
|
660
|
-
#
|
661
|
-
# ```ruby
|
662
|
-
# 'cat and dog'.to_sym #=> :"cat and dog"
|
663
|
-
# ```
|
1571
|
+
# Returns the Symbol corresponding to *str*, creating the symbol if it did not
|
1572
|
+
# previously exist. See Symbol#id2name.
|
1573
|
+
#
|
1574
|
+
# "Koala".intern #=> :Koala
|
1575
|
+
# s = 'cat'.to_sym #=> :cat
|
1576
|
+
# s == :cat #=> true
|
1577
|
+
# s = '@cat'.to_sym #=> :@cat
|
1578
|
+
# s == :@cat #=> true
|
1579
|
+
#
|
1580
|
+
# This can also be used to create symbols that cannot be represented using the
|
1581
|
+
# `:xxx` notation.
|
1582
|
+
#
|
1583
|
+
# 'cat and dog'.to_sym #=> :"cat and dog"
|
1584
|
+
#
|
664
1585
|
def to_sym: () -> Symbol
|
665
1586
|
|
666
|
-
|
667
|
-
|
668
|
-
|
669
|
-
|
670
|
-
|
671
|
-
|
672
|
-
|
1587
|
+
# Returns a copy of `str` with the characters in `from_str` replaced by the
|
1588
|
+
# corresponding characters in `to_str`. If `to_str` is shorter than `from_str`,
|
1589
|
+
# it is padded with its last character in order to maintain the correspondence.
|
1590
|
+
#
|
1591
|
+
# "hello".tr('el', 'ip') #=> "hippo"
|
1592
|
+
# "hello".tr('aeiou', '*') #=> "h*ll*"
|
1593
|
+
# "hello".tr('aeiou', 'AA*') #=> "hAll*"
|
1594
|
+
#
|
1595
|
+
# Both strings may use the `c1-c2` notation to denote ranges of characters, and
|
1596
|
+
# `from_str` may start with a `^`, which denotes all characters except those
|
1597
|
+
# listed.
|
1598
|
+
#
|
1599
|
+
# "hello".tr('a-y', 'b-z') #=> "ifmmp"
|
1600
|
+
# "hello".tr('^aeiou', '*') #=> "*e**o"
|
1601
|
+
#
|
1602
|
+
# The backslash character `\` can be used to escape `^` or `-` and is otherwise
|
1603
|
+
# ignored unless it appears at the end of a range or the end of the `from_str`
|
1604
|
+
# or `to_str`:
|
1605
|
+
#
|
1606
|
+
# "hello^world".tr("\\^aeiou", "*") #=> "h*ll**w*rld"
|
1607
|
+
# "hello-world".tr("a\\-eo", "*") #=> "h*ll**w*rld"
|
1608
|
+
#
|
1609
|
+
# "hello\r\nworld".tr("\r", "") #=> "hello\nworld"
|
1610
|
+
# "hello\r\nworld".tr("\\r", "") #=> "hello\r\nwold"
|
1611
|
+
# "hello\r\nworld".tr("\\\r", "") #=> "hello\nworld"
|
1612
|
+
#
|
1613
|
+
# "X['\\b']".tr("X\\", "") #=> "['b']"
|
1614
|
+
# "X['\\b']".tr("X-\\]", "") #=> "'b'"
|
1615
|
+
#
|
1616
|
+
def tr: (string from_str, string to_str) -> String
|
1617
|
+
|
1618
|
+
# Translates *str* in place, using the same rules as String#tr. Returns *str*,
|
1619
|
+
# or `nil` if no changes were made.
|
1620
|
+
#
|
1621
|
+
def tr!: (string from_str, string to_str) -> String?
|
1622
|
+
|
1623
|
+
# Processes a copy of *str* as described under String#tr, then removes duplicate
|
1624
|
+
# characters in regions that were affected by the translation.
|
1625
|
+
#
|
1626
|
+
# "hello".tr_s('l', 'r') #=> "hero"
|
1627
|
+
# "hello".tr_s('el', '*') #=> "h*o"
|
1628
|
+
# "hello".tr_s('el', 'hx') #=> "hhxo"
|
1629
|
+
#
|
1630
|
+
def tr_s: (string from_str, string to_str) -> String
|
1631
|
+
|
1632
|
+
# Performs String#tr_s processing on *str* in place, returning *str*, or `nil`
|
1633
|
+
# if no changes were made.
|
1634
|
+
#
|
1635
|
+
def tr_s!: (string from_str, string to_str) -> String?
|
1636
|
+
|
1637
|
+
# Returns an unescaped version of the string. This does the inverse of
|
1638
|
+
# String#dump.
|
1639
|
+
#
|
1640
|
+
# "\"hello \\n ''\"".undump #=> "hello \n ''"
|
1641
|
+
#
|
1642
|
+
def undump: () -> String
|
673
1643
|
|
674
|
-
|
1644
|
+
# Unicode Normalization---Returns a normalized form of `str`, using Unicode
|
1645
|
+
# normalizations NFC, NFD, NFKC, or NFKD. The normalization form used is
|
1646
|
+
# determined by `form`, which can be any of the four values `:nfc`, `:nfd`,
|
1647
|
+
# `:nfkc`, or `:nfkd`. The default is `:nfc`.
|
1648
|
+
#
|
1649
|
+
# If the string is not in a Unicode Encoding, then an Exception is raised. In
|
1650
|
+
# this context, 'Unicode Encoding' means any of UTF-8, UTF-16BE/LE, and
|
1651
|
+
# UTF-32BE/LE, as well as GB18030, UCS_2BE, and UCS_4BE. Anything other than
|
1652
|
+
# UTF-8 is implemented by converting to UTF-8, which makes it slower than UTF-8.
|
1653
|
+
#
|
1654
|
+
# "a\u0300".unicode_normalize #=> "\u00E0"
|
1655
|
+
# "a\u0300".unicode_normalize(:nfc) #=> "\u00E0"
|
1656
|
+
# "\u00E0".unicode_normalize(:nfd) #=> "a\u0300"
|
1657
|
+
# "\xE0".force_encoding('ISO-8859-1').unicode_normalize(:nfd)
|
1658
|
+
# #=> Encoding::CompatibilityError raised
|
1659
|
+
#
|
1660
|
+
def unicode_normalize: (?:nfc | :nfd | :nfkc | :nfkd) -> String
|
1661
|
+
|
1662
|
+
# Destructive version of String#unicode_normalize, doing Unicode normalization
|
1663
|
+
# in place.
|
1664
|
+
#
|
1665
|
+
def unicode_normalize!: (?:nfc | :nfd | :nfkc | :nfkd) -> String
|
1666
|
+
|
1667
|
+
# Checks whether `str` is in Unicode normalization form `form`, which can be any
|
1668
|
+
# of the four values `:nfc`, `:nfd`, `:nfkc`, or `:nfkd`. The default is `:nfc`.
|
1669
|
+
#
|
1670
|
+
# If the string is not in a Unicode Encoding, then an Exception is raised. For
|
1671
|
+
# details, see String#unicode_normalize.
|
1672
|
+
#
|
1673
|
+
# "a\u0300".unicode_normalized? #=> false
|
1674
|
+
# "a\u0300".unicode_normalized?(:nfd) #=> true
|
1675
|
+
# "\u00E0".unicode_normalized? #=> true
|
1676
|
+
# "\u00E0".unicode_normalized?(:nfd) #=> false
|
1677
|
+
# "\xE0".force_encoding('ISO-8859-1').unicode_normalized?
|
1678
|
+
# #=> Encoding::CompatibilityError raised
|
1679
|
+
#
|
1680
|
+
def unicode_normalized?: (?:nfc | :nfd | :nfkc | :nfkd) -> bool
|
1681
|
+
|
1682
|
+
# Decodes *str* (which may contain binary data) according to the format string,
|
1683
|
+
# returning an array of each value extracted. The format string consists of a
|
1684
|
+
# sequence of single-character directives, summarized in the table at the end of
|
1685
|
+
# this entry. Each directive may be followed by a number, indicating the number
|
1686
|
+
# of times to repeat with this directive. An asterisk (```*`'') will use up all
|
1687
|
+
# remaining elements. The directives `sSiIlL` may each be followed by an
|
1688
|
+
# underscore (```_`'') or exclamation mark (```!`'') to use the underlying
|
1689
|
+
# platform's native size for the specified type; otherwise, it uses a
|
1690
|
+
# platform-independent consistent size. Spaces are ignored in the format string.
|
1691
|
+
# See also String#unpack1, Array#pack.
|
1692
|
+
#
|
1693
|
+
# "abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "]
|
1694
|
+
# "abc \0\0".unpack('a3a3') #=> ["abc", " \000\000"]
|
1695
|
+
# "abc \0abc \0".unpack('Z*Z*') #=> ["abc ", "abc "]
|
1696
|
+
# "aa".unpack('b8B8') #=> ["10000110", "01100001"]
|
1697
|
+
# "aaa".unpack('h2H2c') #=> ["16", "61", 97]
|
1698
|
+
# "\xfe\xff\xfe\xff".unpack('sS') #=> [-2, 65534]
|
1699
|
+
# "now=20is".unpack('M*') #=> ["now is"]
|
1700
|
+
# "whole".unpack('xax2aX2aX1aX2a') #=> ["h", "e", "l", "l", "o"]
|
1701
|
+
#
|
1702
|
+
# This table summarizes the various formats and the Ruby classes returned by
|
1703
|
+
# each.
|
1704
|
+
#
|
1705
|
+
# Integer | |
|
1706
|
+
# Directive | Returns | Meaning
|
1707
|
+
# ------------------------------------------------------------------
|
1708
|
+
# C | Integer | 8-bit unsigned (unsigned char)
|
1709
|
+
# S | Integer | 16-bit unsigned, native endian (uint16_t)
|
1710
|
+
# L | Integer | 32-bit unsigned, native endian (uint32_t)
|
1711
|
+
# Q | Integer | 64-bit unsigned, native endian (uint64_t)
|
1712
|
+
# J | Integer | pointer width unsigned, native endian (uintptr_t)
|
1713
|
+
# | |
|
1714
|
+
# c | Integer | 8-bit signed (signed char)
|
1715
|
+
# s | Integer | 16-bit signed, native endian (int16_t)
|
1716
|
+
# l | Integer | 32-bit signed, native endian (int32_t)
|
1717
|
+
# q | Integer | 64-bit signed, native endian (int64_t)
|
1718
|
+
# j | Integer | pointer width signed, native endian (intptr_t)
|
1719
|
+
# | |
|
1720
|
+
# S_ S! | Integer | unsigned short, native endian
|
1721
|
+
# I I_ I! | Integer | unsigned int, native endian
|
1722
|
+
# L_ L! | Integer | unsigned long, native endian
|
1723
|
+
# Q_ Q! | Integer | unsigned long long, native endian (ArgumentError
|
1724
|
+
# | | if the platform has no long long type.)
|
1725
|
+
# J! | Integer | uintptr_t, native endian (same with J)
|
1726
|
+
# | |
|
1727
|
+
# s_ s! | Integer | signed short, native endian
|
1728
|
+
# i i_ i! | Integer | signed int, native endian
|
1729
|
+
# l_ l! | Integer | signed long, native endian
|
1730
|
+
# q_ q! | Integer | signed long long, native endian (ArgumentError
|
1731
|
+
# | | if the platform has no long long type.)
|
1732
|
+
# j! | Integer | intptr_t, native endian (same with j)
|
1733
|
+
# | |
|
1734
|
+
# S> s> S!> s!> | Integer | same as the directives without ">" except
|
1735
|
+
# L> l> L!> l!> | | big endian
|
1736
|
+
# I!> i!> | |
|
1737
|
+
# Q> q> Q!> q!> | | "S>" is same as "n"
|
1738
|
+
# J> j> J!> j!> | | "L>" is same as "N"
|
1739
|
+
# | |
|
1740
|
+
# S< s< S!< s!< | Integer | same as the directives without "<" except
|
1741
|
+
# L< l< L!< l!< | | little endian
|
1742
|
+
# I!< i!< | |
|
1743
|
+
# Q< q< Q!< q!< | | "S<" is same as "v"
|
1744
|
+
# J< j< J!< j!< | | "L<" is same as "V"
|
1745
|
+
# | |
|
1746
|
+
# n | Integer | 16-bit unsigned, network (big-endian) byte order
|
1747
|
+
# N | Integer | 32-bit unsigned, network (big-endian) byte order
|
1748
|
+
# v | Integer | 16-bit unsigned, VAX (little-endian) byte order
|
1749
|
+
# V | Integer | 32-bit unsigned, VAX (little-endian) byte order
|
1750
|
+
# | |
|
1751
|
+
# U | Integer | UTF-8 character
|
1752
|
+
# w | Integer | BER-compressed integer (see Array.pack)
|
1753
|
+
#
|
1754
|
+
# Float | |
|
1755
|
+
# Directive | Returns | Meaning
|
1756
|
+
# -----------------------------------------------------------------
|
1757
|
+
# D d | Float | double-precision, native format
|
1758
|
+
# F f | Float | single-precision, native format
|
1759
|
+
# E | Float | double-precision, little-endian byte order
|
1760
|
+
# e | Float | single-precision, little-endian byte order
|
1761
|
+
# G | Float | double-precision, network (big-endian) byte order
|
1762
|
+
# g | Float | single-precision, network (big-endian) byte order
|
1763
|
+
#
|
1764
|
+
# String | |
|
1765
|
+
# Directive | Returns | Meaning
|
1766
|
+
# -----------------------------------------------------------------
|
1767
|
+
# A | String | arbitrary binary string (remove trailing nulls and ASCII spaces)
|
1768
|
+
# a | String | arbitrary binary string
|
1769
|
+
# Z | String | null-terminated string
|
1770
|
+
# B | String | bit string (MSB first)
|
1771
|
+
# b | String | bit string (LSB first)
|
1772
|
+
# H | String | hex string (high nibble first)
|
1773
|
+
# h | String | hex string (low nibble first)
|
1774
|
+
# u | String | UU-encoded string
|
1775
|
+
# M | String | quoted-printable, MIME encoding (see RFC2045)
|
1776
|
+
# m | String | base64 encoded string (RFC 2045) (default)
|
1777
|
+
# | | base64 encoded string (RFC 4648) if followed by 0
|
1778
|
+
# P | String | pointer to a structure (fixed-length string)
|
1779
|
+
# p | String | pointer to a null-terminated string
|
1780
|
+
#
|
1781
|
+
# Misc. | |
|
1782
|
+
# Directive | Returns | Meaning
|
1783
|
+
# -----------------------------------------------------------------
|
1784
|
+
# @ | --- | skip to the offset given by the length argument
|
1785
|
+
# X | --- | skip backward one byte
|
1786
|
+
# x | --- | skip forward one byte
|
1787
|
+
#
|
1788
|
+
# HISTORY
|
1789
|
+
#
|
1790
|
+
# * J, J! j, and j! are available since Ruby 2.3.
|
1791
|
+
# * Q_, Q!, q_, and q! are available since Ruby 2.1.
|
1792
|
+
# * I!<, i!<, I!>, and i!> are available since Ruby 1.9.3.
|
1793
|
+
#
|
1794
|
+
#
|
1795
|
+
def unpack: (String format) -> Array[Integer | Float | String | nil]
|
1796
|
+
|
1797
|
+
# Decodes *str* (which may contain binary data) according to the format string,
|
1798
|
+
# returning the first value extracted. See also String#unpack, Array#pack.
|
1799
|
+
#
|
1800
|
+
# Contrast with String#unpack:
|
1801
|
+
#
|
1802
|
+
# "abc \0\0abc \0\0".unpack('A6Z6') #=> ["abc", "abc "]
|
1803
|
+
# "abc \0\0abc \0\0".unpack1('A6Z6') #=> "abc"
|
1804
|
+
#
|
1805
|
+
# In that case data would be lost but often it's the case that the array only
|
1806
|
+
# holds one value, especially when unpacking binary data. For instance:
|
1807
|
+
#
|
1808
|
+
# "xffx00x00x00".unpack("l") #=> [255] "xffx00x00x00".unpack1("l")
|
1809
|
+
# #=> 255
|
1810
|
+
#
|
1811
|
+
# Thus unpack1 is convenient, makes clear the intention and signals the expected
|
1812
|
+
# return value to those reading the code.
|
1813
|
+
#
|
1814
|
+
def unpack1: (String format) -> (Integer | Float | String | nil)
|
675
1815
|
|
676
1816
|
# Returns a copy of *str* with all lowercase letters replaced with their
|
677
1817
|
# uppercase counterparts.
|
678
|
-
#
|
679
|
-
# See
|
680
|
-
#
|
681
|
-
#
|
682
|
-
#
|
683
|
-
# "hEllO".upcase #=> "HELLO"
|
684
|
-
# ```
|
1818
|
+
#
|
1819
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
1820
|
+
#
|
1821
|
+
# "hEllO".upcase #=> "HELLO"
|
1822
|
+
#
|
685
1823
|
def upcase: () -> String
|
686
|
-
|
687
|
-
|
688
|
-
|
689
|
-
|
690
|
-
#
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
1824
|
+
| (:ascii | :lithuanian | :turkic) -> String
|
1825
|
+
| (:lithuanian, :turkic) -> String
|
1826
|
+
| (:turkic, :lithuanian) -> String
|
1827
|
+
|
1828
|
+
# Upcases the contents of *str*, returning `nil` if no changes were made.
|
1829
|
+
#
|
1830
|
+
# See String#downcase for meaning of `options` and use with different encodings.
|
1831
|
+
#
|
1832
|
+
def upcase!: () -> self?
|
1833
|
+
| (:ascii | :lithuanian | :turkic) -> self?
|
1834
|
+
| (:lithuanian, :turkic) -> self?
|
1835
|
+
| (:turkic, :lithuanian) -> self?
|
1836
|
+
|
1837
|
+
# Iterates through successive values, starting at *str* and ending at
|
1838
|
+
# *other_str* inclusive, passing each value in turn to the block. The
|
1839
|
+
# String#succ method is used to generate each value. If optional second
|
1840
|
+
# argument exclusive is omitted or is false, the last value will be included;
|
1841
|
+
# otherwise it will be excluded.
|
1842
|
+
#
|
1843
|
+
# If no block is given, an enumerator is returned instead.
|
1844
|
+
#
|
1845
|
+
# "a8".upto("b6") {|s| print s, ' ' }
|
1846
|
+
# for s in "a8".."b6"
|
1847
|
+
# print s, ' '
|
1848
|
+
# end
|
1849
|
+
#
|
1850
|
+
# *produces:*
|
1851
|
+
#
|
1852
|
+
# a8 a9 b0 b1 b2 b3 b4 b5 b6
|
1853
|
+
# a8 a9 b0 b1 b2 b3 b4 b5 b6
|
1854
|
+
#
|
1855
|
+
# If *str* and *other_str* contains only ascii numeric characters, both are
|
1856
|
+
# recognized as decimal numbers. In addition, the width of string (e.g. leading
|
1857
|
+
# zeros) is handled appropriately.
|
1858
|
+
#
|
1859
|
+
# "9".upto("11").to_a #=> ["9", "10", "11"]
|
1860
|
+
# "25".upto("5").to_a #=> []
|
1861
|
+
# "07".upto("11").to_a #=> ["07", "08", "09", "10", "11"]
|
1862
|
+
#
|
1863
|
+
def upto: (string other_str, ?bool exclusive) -> Enumerator[String, self]
|
1864
|
+
| (string other_str, ?bool exclusive) { (String s) -> void } -> self
|
695
1865
|
|
696
1866
|
# Returns true for a string which is encoded correctly.
|
697
|
-
#
|
698
|
-
#
|
699
|
-
#
|
700
|
-
#
|
701
|
-
#
|
702
|
-
# ```
|
1867
|
+
#
|
1868
|
+
# "\xc2\xa1".force_encoding("UTF-8").valid_encoding? #=> true
|
1869
|
+
# "\xc2".force_encoding("UTF-8").valid_encoding? #=> false
|
1870
|
+
# "\x80".force_encoding("UTF-8").valid_encoding? #=> false
|
1871
|
+
#
|
703
1872
|
def valid_encoding?: () -> bool
|
704
1873
|
|
705
|
-
|
706
|
-
|
707
|
-
|
708
|
-
|
709
|
-
|
710
|
-
|
711
|
-
|
712
|
-
|
713
|
-
|
714
|
-
|
715
|
-
|
716
|
-
|
717
|
-
|
718
|
-
|
719
|
-
|
720
|
-
|
721
|
-
|
722
|
-
|
723
|
-
|
724
|
-
|
725
|
-
|
726
|
-
def encode!: (
|
727
|
-
?(Encoding | String) encoding,
|
728
|
-
?(Encoding | String) from_encoding,
|
729
|
-
?invalid: :replace ?,
|
730
|
-
?undef: :replace ?,
|
731
|
-
?replace: String,
|
732
|
-
?fallback: Hash[String, String] | Proc | Method,
|
733
|
-
?xml: :text | :attr,
|
734
|
-
?universal_newline: TrueClass,
|
735
|
-
?cr_newline: TrueClass,
|
736
|
-
?crlf_newline: TrueClass
|
737
|
-
) -> self
|
738
|
-
|
739
|
-
def +@: () -> String
|
740
|
-
|
741
|
-
def -@: () -> String
|
742
|
-
|
743
|
-
def unicode_normalize: (?(:nfc | :nfd | :nfkc | :nfkd)) -> String
|
744
|
-
|
745
|
-
def unicode_normalize!: (?(:nfc | :nfd | :nfkc | :nfkd)) -> String
|
746
|
-
|
747
|
-
def casecmp?: (String other) -> bool
|
748
|
-
| (untyped other) -> nil
|
749
|
-
|
750
|
-
def []=: (Integer pos, String new_str) -> String
|
751
|
-
| (Integer begin_pos, Integer end_pos, String new_str) -> String
|
752
|
-
| (::Range[Integer] range, String new_str) -> String
|
753
|
-
| (Regexp regexp, String new_str) -> String
|
754
|
-
| (Regexp regexp, Integer capture, String new_str) -> String
|
755
|
-
| (Regexp regexp, String name, String new_str) -> String
|
756
|
-
| (String other_str, String new_str) -> String
|
757
|
-
|
758
|
-
def undump: () -> String
|
759
|
-
|
760
|
-
def grapheme_clusters: () -> ::Array[::String]
|
761
|
-
|
762
|
-
def reverse!: () -> String
|
763
|
-
|
764
|
-
def each_grapheme_cluster: () { (String grapheme) -> untyped } -> self
|
765
|
-
| () -> ::Enumerator[String, self]
|
766
|
-
|
767
|
-
def unpack1: (String format) -> (Integer | Float | String | nil)
|
768
|
-
|
769
|
-
def unicode_normalized?: (?(:nfc | :nfd | :nfkc | :nfkd)) -> bool
|
1874
|
+
private
|
1875
|
+
|
1876
|
+
# Returns a new string object containing a copy of *str*.
|
1877
|
+
#
|
1878
|
+
# The optional *encoding* keyword argument specifies the encoding of the new
|
1879
|
+
# string. If not specified, the encoding of *str* is used (or ASCII-8BIT, if
|
1880
|
+
# *str* is not specified).
|
1881
|
+
#
|
1882
|
+
# The optional *capacity* keyword argument specifies the size of the internal
|
1883
|
+
# buffer. This may improve performance, when the string will be concatenated
|
1884
|
+
# many times (causing many realloc calls).
|
1885
|
+
#
|
1886
|
+
def initialize: (?string str, ?encoding: Encoding | string, ?capacity: int) -> void
|
1887
|
+
|
1888
|
+
# Replaces the contents of *str* with the corresponding values in *other_str*.
|
1889
|
+
#
|
1890
|
+
# s = "hello" #=> "hello"
|
1891
|
+
# s.replace "world" #=> "world"
|
1892
|
+
#
|
1893
|
+
alias initialize_copy replace
|
770
1894
|
end
|