rbs 3.0.0.dev.2 → 3.0.0.dev.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/comments.yml +2 -1
- data/.github/workflows/ruby.yml +4 -0
- data/Gemfile.lock +11 -11
- data/Rakefile +2 -2
- data/Steepfile +1 -1
- data/core/array.rbs +573 -423
- data/core/basic_object.rbs +11 -39
- data/core/binding.rbs +1 -1
- data/core/builtin.rbs +8 -0
- data/core/class.rbs +37 -0
- data/core/comparable.rbs +7 -18
- data/core/complex.rbs +2 -2
- data/core/data.rbs +419 -0
- data/core/dir.rbs +52 -104
- data/core/encoding.rbs +22 -181
- data/core/enumerable.rbs +212 -175
- data/core/enumerator/product.rbs +96 -0
- data/core/enumerator.rbs +57 -8
- data/core/errors.rbs +8 -2
- data/core/exception.rbs +41 -0
- data/core/fiber.rbs +95 -12
- data/core/file.rbs +840 -275
- data/core/file_test.rbs +34 -19
- data/core/float.rbs +40 -96
- data/core/gc.rbs +15 -3
- data/core/hash.rbs +113 -175
- data/core/integer.rbs +85 -145
- data/core/io/buffer.rbs +187 -60
- data/core/io/wait.rbs +28 -16
- data/core/io.rbs +1859 -1389
- data/core/kernel.rbs +525 -961
- data/core/match_data.rbs +306 -142
- data/core/math.rbs +506 -234
- data/core/method.rbs +0 -24
- data/core/module.rbs +110 -17
- data/core/nil_class.rbs +2 -0
- data/core/numeric.rbs +76 -144
- data/core/object.rbs +88 -212
- data/core/proc.rbs +17 -5
- data/core/process.rbs +22 -5
- data/core/ractor.rbs +1 -1
- data/core/random.rbs +20 -3
- data/core/range.rbs +91 -89
- data/core/rational.rbs +2 -3
- data/core/rbs/unnamed/argf.rbs +177 -120
- data/core/rbs/unnamed/env_class.rbs +89 -163
- data/core/rbs/unnamed/random.rbs +36 -12
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +462 -272
- data/core/ruby_vm.rbs +210 -0
- data/{stdlib/set/0 → core}/set.rbs +43 -47
- data/core/string.rbs +1403 -1332
- data/core/string_io.rbs +191 -107
- data/core/struct.rbs +67 -63
- data/core/symbol.rbs +187 -201
- data/core/thread.rbs +40 -35
- data/core/time.rbs +902 -826
- data/core/trace_point.rbs +55 -6
- data/core/unbound_method.rbs +48 -24
- data/docs/collection.md +4 -0
- data/docs/syntax.md +55 -0
- data/ext/rbs_extension/parser.c +5 -6
- data/lib/rbs/cli.rb +6 -1
- data/lib/rbs/collection/cleaner.rb +8 -1
- data/lib/rbs/collection/config/lockfile.rb +3 -1
- data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
- data/lib/rbs/collection/config.rb +1 -1
- data/lib/rbs/collection/sources/git.rb +9 -2
- data/lib/rbs/collection/sources/local.rb +79 -0
- data/lib/rbs/collection/sources.rb +8 -1
- data/lib/rbs/environment.rb +6 -5
- data/lib/rbs/environment_loader.rb +3 -2
- data/lib/rbs/errors.rb +18 -0
- data/lib/rbs/locator.rb +26 -7
- data/lib/rbs/sorter.rb +2 -2
- data/lib/rbs/version.rb +1 -1
- data/sig/collection/sources.rbs +32 -3
- data/sig/environment.rbs +2 -3
- data/sig/locator.rbs +14 -2
- data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
- data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
- data/stdlib/cgi/0/core.rbs +16 -0
- data/stdlib/coverage/0/coverage.rbs +50 -8
- data/stdlib/csv/0/csv.rbs +1 -1
- data/stdlib/date/0/date.rbs +856 -726
- data/stdlib/date/0/date_time.rbs +83 -210
- data/stdlib/erb/0/erb.rbs +13 -36
- data/stdlib/etc/0/etc.rbs +127 -20
- data/stdlib/fileutils/0/fileutils.rbs +1290 -381
- data/stdlib/logger/0/logger.rbs +466 -316
- data/stdlib/net-http/0/net-http.rbs +2211 -534
- data/stdlib/nkf/0/nkf.rbs +5 -5
- data/stdlib/objspace/0/objspace.rbs +31 -14
- data/stdlib/openssl/0/openssl.rbs +11 -7
- data/stdlib/optparse/0/optparse.rbs +20 -17
- data/stdlib/pathname/0/pathname.rbs +21 -4
- data/stdlib/pstore/0/pstore.rbs +378 -154
- data/stdlib/pty/0/pty.rbs +24 -8
- data/stdlib/ripper/0/ripper.rbs +1650 -0
- data/stdlib/socket/0/addrinfo.rbs +9 -15
- data/stdlib/socket/0/socket.rbs +36 -3
- data/stdlib/strscan/0/string_scanner.rbs +7 -5
- data/stdlib/tempfile/0/tempfile.rbs +104 -44
- data/stdlib/time/0/time.rbs +2 -2
- data/stdlib/uri/0/file.rbs +5 -0
- data/stdlib/uri/0/generic.rbs +2 -2
- data/stdlib/yaml/0/yaml.rbs +2 -2
- data/stdlib/zlib/0/zlib.rbs +1 -1
- metadata +8 -6
- data/core/deprecated.rbs +0 -9
- data/sig/shims/ripper.rbs +0 -8
data/core/match_data.rbs
CHANGED
|
@@ -48,35 +48,37 @@ class MatchData
|
|
|
48
48
|
public
|
|
49
49
|
|
|
50
50
|
# <!-- rdoc-file=re.c -->
|
|
51
|
-
#
|
|
52
|
-
#
|
|
51
|
+
# Returns `true` if `object` is another MatchData object whose target string,
|
|
52
|
+
# regexp, match, and captures are the same as `self`, `false` otherwise.
|
|
53
|
+
#
|
|
54
|
+
# MatchData#eql? is an alias for MatchData#==.
|
|
53
55
|
#
|
|
54
56
|
def ==: (untyped other) -> bool
|
|
55
57
|
|
|
56
58
|
# <!--
|
|
57
59
|
# rdoc-file=re.c
|
|
58
|
-
# -
|
|
59
|
-
# -
|
|
60
|
-
# -
|
|
61
|
-
# -
|
|
60
|
+
# - matchdata[index] -> string or nil
|
|
61
|
+
# - matchdata[start, length] -> array
|
|
62
|
+
# - matchdata[range] -> array
|
|
63
|
+
# - matchdata[name] -> string or nil
|
|
62
64
|
# -->
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
# variable `$&`, and returns the entire matched string. `mtch[1]`, `mtch[2]`,
|
|
66
|
-
# and so on return the values of the matched backreferences (portions of the
|
|
67
|
-
# pattern between parentheses).
|
|
65
|
+
# When arguments `index`, +start and `length`, or `range` are given, returns
|
|
66
|
+
# match and captures in the style of Array#[]:
|
|
68
67
|
#
|
|
69
68
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
70
|
-
#
|
|
71
|
-
# m[0]
|
|
72
|
-
# m[1, 2]
|
|
73
|
-
# m[1..3]
|
|
74
|
-
# m[-3, 2]
|
|
69
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
70
|
+
# m[0] # => "HX1138"
|
|
71
|
+
# m[1, 2] # => ["H", "X"]
|
|
72
|
+
# m[1..3] # => ["H", "X", "113"]
|
|
73
|
+
# m[-3, 2] # => ["X", "113"]
|
|
74
|
+
#
|
|
75
|
+
# When string or symbol argument `name` is given, returns the matched substring
|
|
76
|
+
# for the given name:
|
|
75
77
|
#
|
|
76
|
-
# m = /(?<foo
|
|
77
|
-
#
|
|
78
|
-
# m[
|
|
79
|
-
# m[:
|
|
78
|
+
# m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
|
|
79
|
+
# # => #<MatchData "hoge" foo:"h" bar:"ge">
|
|
80
|
+
# m['foo'] # => "h"
|
|
81
|
+
# m[:bar] # => "ge"
|
|
80
82
|
#
|
|
81
83
|
def []: (Integer idx) -> String?
|
|
82
84
|
| (Integer start, Integer length) -> ::Array[String?]
|
|
@@ -85,69 +87,159 @@ class MatchData
|
|
|
85
87
|
|
|
86
88
|
# <!--
|
|
87
89
|
# rdoc-file=re.c
|
|
88
|
-
# -
|
|
90
|
+
# - begin(n) -> integer
|
|
91
|
+
# - begin(name) -> integer
|
|
89
92
|
# -->
|
|
90
|
-
# Returns the offset
|
|
91
|
-
#
|
|
93
|
+
# Returns the offset (in characters) of the beginning of the specified match.
|
|
94
|
+
#
|
|
95
|
+
# When non-negative integer argument `n` is given, returns the offset of the
|
|
96
|
+
# beginning of the `n`th match:
|
|
92
97
|
#
|
|
93
98
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
94
|
-
#
|
|
95
|
-
# m
|
|
99
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
100
|
+
# m[0] # => "HX1138"
|
|
101
|
+
# m.begin(0) # => 1
|
|
102
|
+
# m[3] # => "113"
|
|
103
|
+
# m.begin(3) # => 3
|
|
104
|
+
#
|
|
105
|
+
# m = /(т)(е)(с)/.match('тест')
|
|
106
|
+
# # => #<MatchData "тес" 1:"т" 2:"е" 3:"с">
|
|
107
|
+
# m[0] # => "тес"
|
|
108
|
+
# m.begin(0) # => 0
|
|
109
|
+
# m[3] # => "с"
|
|
110
|
+
# m.begin(3) # => 2
|
|
111
|
+
#
|
|
112
|
+
# When string or symbol argument `name` is given, returns the offset of the
|
|
113
|
+
# beginning for the named match:
|
|
96
114
|
#
|
|
97
115
|
# m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
98
|
-
#
|
|
99
|
-
#
|
|
116
|
+
# # => #<MatchData "hog" foo:"h" bar:"g">
|
|
117
|
+
# m[:foo] # => "h"
|
|
118
|
+
# m.begin('foo') # => 0
|
|
119
|
+
# m[:bar] # => "g"
|
|
120
|
+
# m.begin(:bar) # => 2
|
|
121
|
+
#
|
|
122
|
+
# Related: MatchData#end, MatchData#offset, MatchData#byteoffset.
|
|
100
123
|
#
|
|
101
124
|
def begin: (Integer | String | Symbol n_or_name) -> Integer?
|
|
102
125
|
|
|
103
126
|
# <!--
|
|
104
127
|
# rdoc-file=re.c
|
|
105
|
-
# - mtch.
|
|
128
|
+
# - mtch.byteoffset(n) -> array
|
|
106
129
|
# -->
|
|
107
|
-
# Returns
|
|
130
|
+
# Returns a two-element array containing the beginning and ending byte-based
|
|
131
|
+
# offsets of the *n*th match. *n* can be a string or symbol to reference a named
|
|
132
|
+
# capture.
|
|
133
|
+
#
|
|
134
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
135
|
+
# m.byteoffset(0) #=> [1, 7]
|
|
136
|
+
# m.byteoffset(4) #=> [6, 7]
|
|
108
137
|
#
|
|
109
|
-
#
|
|
110
|
-
#
|
|
111
|
-
#
|
|
112
|
-
#
|
|
113
|
-
|
|
138
|
+
# m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
139
|
+
# p m.byteoffset(:foo) #=> [0, 1]
|
|
140
|
+
# p m.byteoffset(:bar) #=> [2, 3]
|
|
141
|
+
#
|
|
142
|
+
def byteoffset: (Integer | Symbol | String n_or_name) -> ([ Integer, Integer ] | [ nil, nil ])
|
|
143
|
+
|
|
144
|
+
# <!--
|
|
145
|
+
# rdoc-file=re.c
|
|
146
|
+
# - captures -> array
|
|
147
|
+
# -->
|
|
148
|
+
# Returns the array of captures, which are all matches except `m[0]`:
|
|
149
|
+
#
|
|
150
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
151
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
152
|
+
# m[0] # => "HX1138"
|
|
153
|
+
# m.captures # => ["H", "X", "113", "8"]
|
|
154
|
+
#
|
|
155
|
+
# Related: MatchData.to_a.
|
|
114
156
|
#
|
|
115
157
|
def captures: () -> ::Array[String?]
|
|
116
158
|
|
|
159
|
+
# <!-- rdoc-file=re.c -->
|
|
160
|
+
# Returns the array of captures, which are all matches except `m[0]`:
|
|
161
|
+
#
|
|
162
|
+
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
163
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
164
|
+
# m[0] # => "HX1138"
|
|
165
|
+
# m.captures # => ["H", "X", "113", "8"]
|
|
166
|
+
#
|
|
167
|
+
# Related: MatchData.to_a.
|
|
168
|
+
#
|
|
169
|
+
alias deconstruct captures
|
|
170
|
+
|
|
171
|
+
# <!--
|
|
172
|
+
# rdoc-file=re.c
|
|
173
|
+
# - deconstruct_keys(array_of_names) -> hash
|
|
174
|
+
# -->
|
|
175
|
+
# Returns a hash of the named captures for the given names.
|
|
176
|
+
#
|
|
177
|
+
# m = /(?<hours>\d{2}):(?<minutes>\d{2}):(?<seconds>\d{2})/.match("18:37:22")
|
|
178
|
+
# m.deconstruct_keys([:hours, :minutes]) # => {:hours => "18", :minutes => "37"}
|
|
179
|
+
# m.deconstruct_keys(nil) # => {:hours => "18", :minutes => "37", :seconds => "22"}
|
|
180
|
+
#
|
|
181
|
+
# Returns an empty hash of no named captures were defined:
|
|
182
|
+
#
|
|
183
|
+
# m = /(\d{2}):(\d{2}):(\d{2})/.match("18:37:22")
|
|
184
|
+
# m.deconstruct_keys(nil) # => {}
|
|
185
|
+
#
|
|
186
|
+
def deconstruct_keys: (Array[Symbol]?) -> Hash[Symbol, String?]
|
|
187
|
+
|
|
117
188
|
# <!--
|
|
118
189
|
# rdoc-file=re.c
|
|
119
|
-
# -
|
|
190
|
+
# - end(n) -> integer
|
|
191
|
+
# - end(name) -> integer
|
|
120
192
|
# -->
|
|
121
|
-
# Returns the offset
|
|
122
|
-
#
|
|
123
|
-
#
|
|
193
|
+
# Returns the offset (in characters) of the end of the specified match.
|
|
194
|
+
#
|
|
195
|
+
# When non-negative integer argument `n` is given, returns the offset of the end
|
|
196
|
+
# of the `n`th match:
|
|
124
197
|
#
|
|
125
198
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
126
|
-
#
|
|
127
|
-
# m
|
|
199
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
200
|
+
# m[0] # => "HX1138"
|
|
201
|
+
# m.end(0) # => 7
|
|
202
|
+
# m[3] # => "113"
|
|
203
|
+
# m.end(3) # => 6
|
|
204
|
+
#
|
|
205
|
+
# m = /(т)(е)(с)/.match('тест')
|
|
206
|
+
# # => #<MatchData "тес" 1:"т" 2:"е" 3:"с">
|
|
207
|
+
# m[0] # => "тес"
|
|
208
|
+
# m.end(0) # => 3
|
|
209
|
+
# m[3] # => "с"
|
|
210
|
+
# m.end(3) # => 3
|
|
211
|
+
#
|
|
212
|
+
# When string or symbol argument `name` is given, returns the offset of the end
|
|
213
|
+
# for the named match:
|
|
128
214
|
#
|
|
129
215
|
# m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
130
|
-
#
|
|
131
|
-
#
|
|
216
|
+
# # => #<MatchData "hog" foo:"h" bar:"g">
|
|
217
|
+
# m[:foo] # => "h"
|
|
218
|
+
# m.end('foo') # => 1
|
|
219
|
+
# m[:bar] # => "g"
|
|
220
|
+
# m.end(:bar) # => 3
|
|
221
|
+
#
|
|
222
|
+
# Related: MatchData#begin, MatchData#offset, MatchData#byteoffset.
|
|
132
223
|
#
|
|
133
224
|
def end: (Integer | String | Symbol n_or_name) -> Integer?
|
|
134
225
|
|
|
135
226
|
# <!--
|
|
136
227
|
# rdoc-file=re.c
|
|
137
|
-
# -
|
|
138
|
-
# - mtch.eql?(mtch2) -> true or false
|
|
228
|
+
# - matchdata == object -> true or false
|
|
139
229
|
# -->
|
|
140
|
-
#
|
|
141
|
-
#
|
|
230
|
+
# Returns `true` if `object` is another MatchData object whose target string,
|
|
231
|
+
# regexp, match, and captures are the same as `self`, `false` otherwise.
|
|
232
|
+
#
|
|
233
|
+
# MatchData#eql? is an alias for MatchData#==.
|
|
142
234
|
#
|
|
143
235
|
def eql?: (untyped other) -> bool
|
|
144
236
|
|
|
145
237
|
# <!--
|
|
146
238
|
# rdoc-file=re.c
|
|
147
|
-
# -
|
|
239
|
+
# - hash -> integer
|
|
148
240
|
# -->
|
|
149
|
-
#
|
|
150
|
-
#
|
|
241
|
+
# Returns the integer hash value for `self`, based on the target string, regexp,
|
|
242
|
+
# match, and captures.
|
|
151
243
|
#
|
|
152
244
|
# See also Object#hash.
|
|
153
245
|
#
|
|
@@ -155,230 +247,302 @@ class MatchData
|
|
|
155
247
|
|
|
156
248
|
# <!--
|
|
157
249
|
# rdoc-file=re.c
|
|
158
|
-
# -
|
|
250
|
+
# - inspect -> string
|
|
159
251
|
# -->
|
|
160
|
-
# Returns a
|
|
252
|
+
# Returns a string representation of `self`:
|
|
161
253
|
#
|
|
162
|
-
#
|
|
163
|
-
#
|
|
254
|
+
# m = /.$/.match("foo")
|
|
255
|
+
# # => #<MatchData "o">
|
|
256
|
+
# m.inspect # => "#<MatchData \"o\">"
|
|
164
257
|
#
|
|
165
|
-
#
|
|
166
|
-
#
|
|
258
|
+
# m = /(.)(.)(.)/.match("foo")
|
|
259
|
+
# # => #<MatchData "foo" 1:"f" 2:"o" 3:"o">
|
|
260
|
+
# m.inspect # => "#<MatchData \"foo\" 1:\"f\" 2:\"o\
|
|
167
261
|
#
|
|
168
|
-
#
|
|
169
|
-
#
|
|
262
|
+
# m = /(.)(.)?(.)/.match("fo")
|
|
263
|
+
# # => #<MatchData "fo" 1:"f" 2:nil 3:"o">
|
|
264
|
+
# m.inspect # => "#<MatchData \"fo\" 1:\"f\" 2:nil 3:\"o\">"
|
|
170
265
|
#
|
|
171
|
-
#
|
|
172
|
-
# #=> #<MatchData "hog" foo:"h" bar:"o" baz:"g">
|
|
266
|
+
# Related: MatchData#to_s.
|
|
173
267
|
#
|
|
174
268
|
def inspect: () -> String
|
|
175
269
|
|
|
176
270
|
# <!-- rdoc-file=re.c -->
|
|
177
|
-
# Returns
|
|
271
|
+
# Returns size of the match array:
|
|
178
272
|
#
|
|
179
273
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
180
|
-
#
|
|
181
|
-
# m.size
|
|
274
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
275
|
+
# m.size # => 5
|
|
276
|
+
#
|
|
277
|
+
# MatchData#length is an alias for MatchData.size.
|
|
182
278
|
#
|
|
183
279
|
def length: () -> Integer
|
|
184
280
|
|
|
185
281
|
# <!--
|
|
186
282
|
# rdoc-file=re.c
|
|
187
|
-
# -
|
|
283
|
+
# - named_captures -> hash
|
|
188
284
|
# -->
|
|
189
|
-
# Returns a
|
|
285
|
+
# Returns a hash of the named captures; each key is a capture name; each value
|
|
286
|
+
# is its captured string or `nil`:
|
|
190
287
|
#
|
|
191
|
-
#
|
|
192
|
-
#
|
|
288
|
+
# m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
|
|
289
|
+
# # => #<MatchData "hoge" foo:"h" bar:"ge">
|
|
290
|
+
# m.named_captures # => {"foo"=>"h", "bar"=>"ge"}
|
|
193
291
|
#
|
|
194
292
|
# m = /(?<a>.)(?<b>.)/.match("01")
|
|
293
|
+
# # => #<MatchData "01" a:"0" b:"1">
|
|
195
294
|
# m.named_captures #=> {"a" => "0", "b" => "1"}
|
|
196
295
|
#
|
|
197
296
|
# m = /(?<a>.)(?<b>.)?/.match("0")
|
|
297
|
+
# # => #<MatchData "0" a:"0" b:nil>
|
|
198
298
|
# m.named_captures #=> {"a" => "0", "b" => nil}
|
|
199
299
|
#
|
|
200
300
|
# m = /(?<a>.)(?<a>.)/.match("01")
|
|
301
|
+
# # => #<MatchData "01" a:"0" a:"1">
|
|
201
302
|
# m.named_captures #=> {"a" => "1"}
|
|
202
303
|
#
|
|
203
|
-
# m = /(?<a>x)|(?<a>y)/.match("x")
|
|
204
|
-
# m.named_captures #=> {"a" => "x"}
|
|
205
|
-
#
|
|
206
304
|
def named_captures: () -> ::Hash[String, String?]
|
|
207
305
|
|
|
208
306
|
# <!--
|
|
209
307
|
# rdoc-file=re.c
|
|
210
|
-
# -
|
|
308
|
+
# - names -> array_of_names
|
|
211
309
|
# -->
|
|
212
|
-
# Returns
|
|
213
|
-
#
|
|
310
|
+
# Returns an array of the capture names (see [Named
|
|
311
|
+
# Captures](rdoc-ref:Regexp@Named+Captures)):
|
|
312
|
+
#
|
|
313
|
+
# m = /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge")
|
|
314
|
+
# # => #<MatchData "hog" foo:"h" bar:"o" baz:"g">
|
|
315
|
+
# m.names # => ["foo", "bar", "baz"]
|
|
316
|
+
#
|
|
317
|
+
# m = /foo/.match('foo') # => #<MatchData "foo">
|
|
318
|
+
# m.names # => [] # No named captures.
|
|
214
319
|
#
|
|
215
|
-
#
|
|
216
|
-
# #=> ["foo", "bar", "baz"]
|
|
320
|
+
# Equivalent to:
|
|
217
321
|
#
|
|
218
|
-
# m = /(?<
|
|
219
|
-
# m.names
|
|
322
|
+
# m = /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge")
|
|
323
|
+
# m.regexp.names # => ["foo", "bar", "baz"]
|
|
220
324
|
#
|
|
221
325
|
def names: () -> ::Array[String]
|
|
222
326
|
|
|
223
327
|
# <!--
|
|
224
328
|
# rdoc-file=re.c
|
|
225
|
-
# -
|
|
329
|
+
# - match(n) -> string or nil
|
|
330
|
+
# - match(name) -> string or nil
|
|
226
331
|
# -->
|
|
227
|
-
# Returns the
|
|
228
|
-
#
|
|
332
|
+
# Returns the matched substring corresponding to the given argument.
|
|
333
|
+
#
|
|
334
|
+
# When non-negative argument `n` is given, returns the matched substring for the
|
|
335
|
+
# `n`th match:
|
|
229
336
|
#
|
|
230
337
|
# m = /(.)(.)(\d+)(\d)(\w)?/.match("THX1138.")
|
|
231
|
-
#
|
|
232
|
-
# m.match(
|
|
233
|
-
# m.match(
|
|
338
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8" 5:nil>
|
|
339
|
+
# m.match(0) # => "HX1138"
|
|
340
|
+
# m.match(4) # => "8"
|
|
341
|
+
# m.match(5) # => nil
|
|
342
|
+
#
|
|
343
|
+
# When string or symbol argument `name` is given, returns the matched substring
|
|
344
|
+
# for the given name:
|
|
234
345
|
#
|
|
235
346
|
# m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
|
|
236
|
-
#
|
|
237
|
-
# m.match(
|
|
347
|
+
# # => #<MatchData "hoge" foo:"h" bar:"ge">
|
|
348
|
+
# m.match('foo') # => "h"
|
|
349
|
+
# m.match(:bar) # => "ge"
|
|
238
350
|
#
|
|
239
351
|
def match: (int | String | Symbol) -> String?
|
|
240
352
|
|
|
241
353
|
# <!--
|
|
242
354
|
# rdoc-file=re.c
|
|
243
|
-
# -
|
|
355
|
+
# - match_length(n) -> integer or nil
|
|
356
|
+
# - match_length(name) -> integer or nil
|
|
244
357
|
# -->
|
|
245
|
-
# Returns the length of the
|
|
246
|
-
#
|
|
358
|
+
# Returns the length (in characters) of the matched substring corresponding to
|
|
359
|
+
# the given argument.
|
|
360
|
+
#
|
|
361
|
+
# When non-negative argument `n` is given, returns the length of the matched
|
|
362
|
+
# substring for the `n`th match:
|
|
247
363
|
#
|
|
248
364
|
# m = /(.)(.)(\d+)(\d)(\w)?/.match("THX1138.")
|
|
249
|
-
#
|
|
250
|
-
# m.match_length(
|
|
251
|
-
# m.match_length(
|
|
365
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8" 5:nil>
|
|
366
|
+
# m.match_length(0) # => 6
|
|
367
|
+
# m.match_length(4) # => 1
|
|
368
|
+
# m.match_length(5) # => nil
|
|
369
|
+
#
|
|
370
|
+
# When string or symbol argument `name` is given, returns the length of the
|
|
371
|
+
# matched substring for the named match:
|
|
252
372
|
#
|
|
253
373
|
# m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
|
|
254
|
-
#
|
|
255
|
-
# m.match_length(
|
|
374
|
+
# # => #<MatchData "hoge" foo:"h" bar:"ge">
|
|
375
|
+
# m.match_length('foo') # => 1
|
|
376
|
+
# m.match_length(:bar) # => 2
|
|
256
377
|
#
|
|
257
378
|
def match_length: (int | String | Symbol) -> Integer?
|
|
258
379
|
|
|
259
380
|
# <!--
|
|
260
381
|
# rdoc-file=re.c
|
|
261
|
-
# -
|
|
382
|
+
# - offset(n) -> [start_offset, end_offset]
|
|
383
|
+
# - offset(name) -> [start_offset, end_offset]
|
|
262
384
|
# -->
|
|
263
|
-
# Returns a
|
|
264
|
-
#
|
|
385
|
+
# Returns a 2-element array containing the beginning and ending offsets (in
|
|
386
|
+
# characters) of the specified match.
|
|
387
|
+
#
|
|
388
|
+
# When non-negative integer argument `n` is given, returns the starting and
|
|
389
|
+
# ending offsets of the `n`th match:
|
|
265
390
|
#
|
|
266
391
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
267
|
-
#
|
|
268
|
-
# m
|
|
392
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
393
|
+
# m[0] # => "HX1138"
|
|
394
|
+
# m.offset(0) # => [1, 7]
|
|
395
|
+
# m[3] # => "113"
|
|
396
|
+
# m.offset(3) # => [3, 6]
|
|
397
|
+
#
|
|
398
|
+
# m = /(т)(е)(с)/.match('тест')
|
|
399
|
+
# # => #<MatchData "тес" 1:"т" 2:"е" 3:"с">
|
|
400
|
+
# m[0] # => "тес"
|
|
401
|
+
# m.offset(0) # => [0, 3]
|
|
402
|
+
# m[3] # => "с"
|
|
403
|
+
# m.offset(3) # => [2, 3]
|
|
404
|
+
#
|
|
405
|
+
# When string or symbol argument `name` is given, returns the starting and
|
|
406
|
+
# ending offsets for the named match:
|
|
269
407
|
#
|
|
270
408
|
# m = /(?<foo>.)(.)(?<bar>.)/.match("hoge")
|
|
271
|
-
#
|
|
272
|
-
#
|
|
409
|
+
# # => #<MatchData "hog" foo:"h" bar:"g">
|
|
410
|
+
# m[:foo] # => "h"
|
|
411
|
+
# m.offset('foo') # => [0, 1]
|
|
412
|
+
# m[:bar] # => "g"
|
|
413
|
+
# m.offset(:bar) # => [2, 3]
|
|
414
|
+
#
|
|
415
|
+
# Related: MatchData#byteoffset, MatchData#begin, MatchData#end.
|
|
273
416
|
#
|
|
274
417
|
def offset: (Integer | Symbol | String n_or_name) -> ([ Integer, Integer ] | [ nil, nil ])
|
|
275
418
|
|
|
276
419
|
# <!--
|
|
277
420
|
# rdoc-file=re.c
|
|
278
|
-
# -
|
|
421
|
+
# - post_match -> str
|
|
279
422
|
# -->
|
|
280
|
-
# Returns the
|
|
281
|
-
# to the
|
|
423
|
+
# Returns the substring of the target string from the end of the first match in
|
|
424
|
+
# `self` (that is, `self[0]`) to the end of the string; equivalent to regexp
|
|
425
|
+
# global variable `$'`:
|
|
282
426
|
#
|
|
283
427
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
284
|
-
#
|
|
428
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
429
|
+
# m[0] # => "HX1138"
|
|
430
|
+
# m.post_match # => ": The Movie"\
|
|
431
|
+
#
|
|
432
|
+
# Related: MatchData.pre_match.
|
|
285
433
|
#
|
|
286
434
|
def post_match: () -> String
|
|
287
435
|
|
|
288
436
|
# <!--
|
|
289
437
|
# rdoc-file=re.c
|
|
290
|
-
# -
|
|
438
|
+
# - pre_match -> string
|
|
291
439
|
# -->
|
|
292
|
-
# Returns the
|
|
293
|
-
#
|
|
440
|
+
# Returns the substring of the target string from its beginning up to the first
|
|
441
|
+
# match in `self` (that is, `self[0]`); equivalent to regexp global variable
|
|
442
|
+
# `$``:
|
|
294
443
|
#
|
|
295
444
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
296
|
-
#
|
|
445
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
446
|
+
# m[0] # => "HX1138"
|
|
447
|
+
# m.pre_match # => "T"
|
|
448
|
+
#
|
|
449
|
+
# Related: MatchData#post_match.
|
|
297
450
|
#
|
|
298
451
|
def pre_match: () -> String
|
|
299
452
|
|
|
300
453
|
# <!--
|
|
301
454
|
# rdoc-file=re.c
|
|
302
|
-
# -
|
|
455
|
+
# - regexp -> regexp
|
|
303
456
|
# -->
|
|
304
|
-
# Returns the regexp
|
|
457
|
+
# Returns the regexp that produced the match:
|
|
305
458
|
#
|
|
306
|
-
# m = /a.*b/.match("abc")
|
|
307
|
-
# m.regexp
|
|
459
|
+
# m = /a.*b/.match("abc") # => #<MatchData "ab">
|
|
460
|
+
# m.regexp # => /a.*b/
|
|
308
461
|
#
|
|
309
462
|
def regexp: () -> Regexp
|
|
310
463
|
|
|
311
464
|
# <!--
|
|
312
465
|
# rdoc-file=re.c
|
|
313
|
-
# -
|
|
314
|
-
# - mtch.size -> integer
|
|
466
|
+
# - size -> integer
|
|
315
467
|
# -->
|
|
316
|
-
# Returns
|
|
468
|
+
# Returns size of the match array:
|
|
317
469
|
#
|
|
318
470
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
319
|
-
#
|
|
320
|
-
# m.size
|
|
471
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
472
|
+
# m.size # => 5
|
|
473
|
+
#
|
|
474
|
+
# MatchData#length is an alias for MatchData.size.
|
|
321
475
|
#
|
|
322
476
|
def size: () -> Integer
|
|
323
477
|
|
|
324
478
|
# <!--
|
|
325
479
|
# rdoc-file=re.c
|
|
326
|
-
# -
|
|
480
|
+
# - string -> string
|
|
327
481
|
# -->
|
|
328
|
-
# Returns
|
|
482
|
+
# Returns the target string if it was frozen; otherwise, returns a frozen copy
|
|
483
|
+
# of the target string:
|
|
329
484
|
#
|
|
330
485
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
331
|
-
#
|
|
486
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
487
|
+
# m.string # => "THX1138."
|
|
332
488
|
#
|
|
333
489
|
def string: () -> String
|
|
334
490
|
|
|
335
491
|
# <!--
|
|
336
492
|
# rdoc-file=re.c
|
|
337
|
-
# -
|
|
493
|
+
# - to_a -> array
|
|
338
494
|
# -->
|
|
339
|
-
# Returns the array of matches
|
|
495
|
+
# Returns the array of matches:
|
|
340
496
|
#
|
|
341
497
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
342
|
-
#
|
|
343
|
-
#
|
|
344
|
-
# Because `to_a` is called when expanding `*`*variable*, there's a useful
|
|
345
|
-
# assignment shortcut for extracting matched fields. This is slightly slower
|
|
346
|
-
# than accessing the fields directly (as an intermediate array is generated).
|
|
498
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
499
|
+
# m.to_a # => ["HX1138", "H", "X", "113", "8"]
|
|
347
500
|
#
|
|
348
|
-
#
|
|
349
|
-
# all #=> "HX1138"
|
|
350
|
-
# f1 #=> "H"
|
|
351
|
-
# f2 #=> "X"
|
|
352
|
-
# f3 #=> "113"
|
|
501
|
+
# Related: MatchData#captures.
|
|
353
502
|
#
|
|
354
503
|
def to_a: () -> ::Array[String?]
|
|
355
504
|
|
|
356
505
|
# <!--
|
|
357
506
|
# rdoc-file=re.c
|
|
358
|
-
# -
|
|
507
|
+
# - to_s -> string
|
|
359
508
|
# -->
|
|
360
|
-
# Returns the
|
|
509
|
+
# Returns the matched string:
|
|
361
510
|
#
|
|
362
511
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138.")
|
|
363
|
-
#
|
|
512
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
513
|
+
# m.to_s # => "HX1138"
|
|
514
|
+
#
|
|
515
|
+
# m = /(?<foo>.)(.)(?<bar>.+)/.match("hoge")
|
|
516
|
+
# # => #<MatchData "hoge" foo:"h" bar:"ge">
|
|
517
|
+
# m.to_s # => "hoge"
|
|
518
|
+
#
|
|
519
|
+
# Related: MatchData.inspect.
|
|
364
520
|
#
|
|
365
521
|
def to_s: () -> String
|
|
366
522
|
|
|
367
523
|
# <!--
|
|
368
524
|
# rdoc-file=re.c
|
|
369
|
-
# -
|
|
525
|
+
# - values_at(*indexes) -> array
|
|
370
526
|
# -->
|
|
371
|
-
#
|
|
372
|
-
#
|
|
527
|
+
# Returns match and captures at the given `indexes`, which may include any
|
|
528
|
+
# mixture of:
|
|
529
|
+
#
|
|
530
|
+
# * Integers.
|
|
531
|
+
# * Ranges.
|
|
532
|
+
# * Names (strings and symbols).
|
|
533
|
+
#
|
|
534
|
+
#
|
|
535
|
+
# Examples:
|
|
373
536
|
#
|
|
374
537
|
# m = /(.)(.)(\d+)(\d)/.match("THX1138: The Movie")
|
|
375
|
-
#
|
|
376
|
-
# m.values_at(0, 2, -2)
|
|
377
|
-
# m.values_at(1..2, -1)
|
|
538
|
+
# # => #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
|
|
539
|
+
# m.values_at(0, 2, -2) # => ["HX1138", "X", "113"]
|
|
540
|
+
# m.values_at(1..2, -1) # => ["H", "X", "8"]
|
|
378
541
|
#
|
|
379
542
|
# m = /(?<a>\d+) *(?<op>[+\-*\/]) *(?<b>\d+)/.match("1 + 2")
|
|
380
|
-
#
|
|
381
|
-
# m.values_at(:a, :b, :op)
|
|
543
|
+
# # => #<MatchData "1 + 2" a:"1" op:"+" b:"2">
|
|
544
|
+
# m.values_at(0, 1..2, :a, :b, :op)
|
|
545
|
+
# # => ["1 + 2", "1", "+", "1", "2", "+"]
|
|
382
546
|
#
|
|
383
547
|
def values_at: (*Integer | Symbol | String n_or_name) -> ::Array[String?]
|
|
384
548
|
|