rbs 3.0.0.dev.2 → 3.0.0.dev.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/comments.yml +2 -1
  3. data/.github/workflows/ruby.yml +4 -0
  4. data/Gemfile.lock +11 -11
  5. data/Rakefile +2 -2
  6. data/Steepfile +1 -1
  7. data/core/array.rbs +573 -423
  8. data/core/basic_object.rbs +11 -39
  9. data/core/binding.rbs +1 -1
  10. data/core/builtin.rbs +8 -0
  11. data/core/class.rbs +37 -0
  12. data/core/comparable.rbs +7 -18
  13. data/core/complex.rbs +2 -2
  14. data/core/data.rbs +419 -0
  15. data/core/dir.rbs +52 -104
  16. data/core/encoding.rbs +22 -181
  17. data/core/enumerable.rbs +212 -175
  18. data/core/enumerator/product.rbs +96 -0
  19. data/core/enumerator.rbs +57 -8
  20. data/core/errors.rbs +8 -2
  21. data/core/exception.rbs +41 -0
  22. data/core/fiber.rbs +95 -12
  23. data/core/file.rbs +840 -275
  24. data/core/file_test.rbs +34 -19
  25. data/core/float.rbs +40 -96
  26. data/core/gc.rbs +15 -3
  27. data/core/hash.rbs +113 -175
  28. data/core/integer.rbs +85 -145
  29. data/core/io/buffer.rbs +187 -60
  30. data/core/io/wait.rbs +28 -16
  31. data/core/io.rbs +1859 -1389
  32. data/core/kernel.rbs +525 -961
  33. data/core/match_data.rbs +306 -142
  34. data/core/math.rbs +506 -234
  35. data/core/method.rbs +0 -24
  36. data/core/module.rbs +110 -17
  37. data/core/nil_class.rbs +2 -0
  38. data/core/numeric.rbs +76 -144
  39. data/core/object.rbs +88 -212
  40. data/core/proc.rbs +17 -5
  41. data/core/process.rbs +22 -5
  42. data/core/ractor.rbs +1 -1
  43. data/core/random.rbs +20 -3
  44. data/core/range.rbs +91 -89
  45. data/core/rational.rbs +2 -3
  46. data/core/rbs/unnamed/argf.rbs +177 -120
  47. data/core/rbs/unnamed/env_class.rbs +89 -163
  48. data/core/rbs/unnamed/random.rbs +36 -12
  49. data/core/refinement.rbs +8 -0
  50. data/core/regexp.rbs +462 -272
  51. data/core/ruby_vm.rbs +210 -0
  52. data/{stdlib/set/0 → core}/set.rbs +43 -47
  53. data/core/string.rbs +1403 -1332
  54. data/core/string_io.rbs +191 -107
  55. data/core/struct.rbs +67 -63
  56. data/core/symbol.rbs +187 -201
  57. data/core/thread.rbs +40 -35
  58. data/core/time.rbs +902 -826
  59. data/core/trace_point.rbs +55 -6
  60. data/core/unbound_method.rbs +48 -24
  61. data/docs/collection.md +4 -0
  62. data/docs/syntax.md +55 -0
  63. data/ext/rbs_extension/parser.c +5 -6
  64. data/lib/rbs/cli.rb +6 -1
  65. data/lib/rbs/collection/cleaner.rb +8 -1
  66. data/lib/rbs/collection/config/lockfile.rb +3 -1
  67. data/lib/rbs/collection/config/lockfile_generator.rb +16 -14
  68. data/lib/rbs/collection/config.rb +1 -1
  69. data/lib/rbs/collection/sources/git.rb +9 -2
  70. data/lib/rbs/collection/sources/local.rb +79 -0
  71. data/lib/rbs/collection/sources.rb +8 -1
  72. data/lib/rbs/environment.rb +6 -5
  73. data/lib/rbs/environment_loader.rb +3 -2
  74. data/lib/rbs/errors.rb +18 -0
  75. data/lib/rbs/locator.rb +26 -7
  76. data/lib/rbs/sorter.rb +2 -2
  77. data/lib/rbs/version.rb +1 -1
  78. data/sig/collection/sources.rbs +32 -3
  79. data/sig/environment.rbs +2 -3
  80. data/sig/locator.rbs +14 -2
  81. data/sig/shims/{abstract_syntax_tree.rbs → _abstract_syntax_tree.rbs} +0 -0
  82. data/stdlib/bigdecimal/0/big_decimal.rbs +16 -13
  83. data/stdlib/cgi/0/core.rbs +16 -0
  84. data/stdlib/coverage/0/coverage.rbs +50 -8
  85. data/stdlib/csv/0/csv.rbs +1 -1
  86. data/stdlib/date/0/date.rbs +856 -726
  87. data/stdlib/date/0/date_time.rbs +83 -210
  88. data/stdlib/erb/0/erb.rbs +13 -36
  89. data/stdlib/etc/0/etc.rbs +127 -20
  90. data/stdlib/fileutils/0/fileutils.rbs +1290 -381
  91. data/stdlib/logger/0/logger.rbs +466 -316
  92. data/stdlib/net-http/0/net-http.rbs +2211 -534
  93. data/stdlib/nkf/0/nkf.rbs +5 -5
  94. data/stdlib/objspace/0/objspace.rbs +31 -14
  95. data/stdlib/openssl/0/openssl.rbs +11 -7
  96. data/stdlib/optparse/0/optparse.rbs +20 -17
  97. data/stdlib/pathname/0/pathname.rbs +21 -4
  98. data/stdlib/pstore/0/pstore.rbs +378 -154
  99. data/stdlib/pty/0/pty.rbs +24 -8
  100. data/stdlib/ripper/0/ripper.rbs +1650 -0
  101. data/stdlib/socket/0/addrinfo.rbs +9 -15
  102. data/stdlib/socket/0/socket.rbs +36 -3
  103. data/stdlib/strscan/0/string_scanner.rbs +7 -5
  104. data/stdlib/tempfile/0/tempfile.rbs +104 -44
  105. data/stdlib/time/0/time.rbs +2 -2
  106. data/stdlib/uri/0/file.rbs +5 -0
  107. data/stdlib/uri/0/generic.rbs +2 -2
  108. data/stdlib/yaml/0/yaml.rbs +2 -2
  109. data/stdlib/zlib/0/zlib.rbs +1 -1
  110. metadata +8 -6
  111. data/core/deprecated.rbs +0 -9
  112. 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
- # Equality---Two matchdata are equal if their target strings, patterns, and
52
- # matched positions are identical.
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
- # - mtch[i] -> str or nil
59
- # - mtch[start, length] -> array
60
- # - mtch[range] -> array
61
- # - mtch[name] -> str or nil
60
+ # - matchdata[index] -> string or nil
61
+ # - matchdata[start, length] -> array
62
+ # - matchdata[range] -> array
63
+ # - matchdata[name] -> string or nil
62
64
  # -->
63
- # Match Reference -- MatchData acts as an array, and may be accessed using the
64
- # normal array indexing techniques. `mtch[0]` is equivalent to the special
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
- # m #=> #<MatchData "HX1138" 1:"H" 2:"X" 3:"113" 4:"8">
71
- # m[0] #=> "HX1138"
72
- # m[1, 2] #=> ["H", "X"]
73
- # m[1..3] #=> ["H", "X", "113"]
74
- # m[-3, 2] #=> ["X", "113"]
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>a+)b/.match("ccaaab")
77
- # m #=> #<MatchData "aaab" foo:"aaa">
78
- # m["foo"] #=> "aaa"
79
- # m[:foo] #=> "aaa"
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
- # - mtch.begin(n) -> integer
90
+ # - begin(n) -> integer
91
+ # - begin(name) -> integer
89
92
  # -->
90
- # Returns the offset of the start of the *n*th element of the match array in the
91
- # string. *n* can be a string or symbol to reference a named capture.
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
- # m.begin(0) #=> 1
95
- # m.begin(2) #=> 2
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
- # p m.begin(:foo) #=> 0
99
- # p m.begin(:bar) #=> 2
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.captures -> array
128
+ # - mtch.byteoffset(n) -> array
106
129
  # -->
107
- # Returns the array of captures; equivalent to `mtch.to_a[1..-1]`.
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
- # f1,f2,f3,f4 = /(.)(.)(\d+)(\d)/.match("THX1138.").captures
110
- # f1 #=> "H"
111
- # f2 #=> "X"
112
- # f3 #=> "113"
113
- # f4 #=> "8"
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
- # - mtch.end(n) -> integer
190
+ # - end(n) -> integer
191
+ # - end(name) -> integer
120
192
  # -->
121
- # Returns the offset of the character immediately following the end of the *n*th
122
- # element of the match array in the string. *n* can be a string or symbol to
123
- # reference a named capture.
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
- # m.end(0) #=> 7
127
- # m.end(2) #=> 3
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
- # p m.end(:foo) #=> 1
131
- # p m.end(:bar) #=> 3
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
- # - mtch == mtch2 -> true or false
138
- # - mtch.eql?(mtch2) -> true or false
228
+ # - matchdata == object -> true or false
139
229
  # -->
140
- # Equality---Two matchdata are equal if their target strings, patterns, and
141
- # matched positions are identical.
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
- # - mtch.hash -> integer
239
+ # - hash -> integer
148
240
  # -->
149
- # Produce a hash based on the target string, regexp and matched positions of
150
- # this matchdata.
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
- # - mtch.inspect -> str
250
+ # - inspect -> string
159
251
  # -->
160
- # Returns a printable version of *mtch*.
252
+ # Returns a string representation of `self`:
161
253
  #
162
- # puts /.$/.match("foo").inspect
163
- # #=> #<MatchData "o">
254
+ # m = /.$/.match("foo")
255
+ # # => #<MatchData "o">
256
+ # m.inspect # => "#<MatchData \"o\">"
164
257
  #
165
- # puts /(.)(.)(.)/.match("foo").inspect
166
- # #=> #<MatchData "foo" 1:"f" 2:"o" 3:"o">
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
- # puts /(.)(.)?(.)/.match("fo").inspect
169
- # #=> #<MatchData "fo" 1:"f" 2:nil 3:"o">
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
- # puts /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").inspect
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 the number of elements in the match array.
271
+ # Returns size of the match array:
178
272
  #
179
273
  # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
180
- # m.length #=> 5
181
- # m.size #=> 5
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
- # - mtch.named_captures -> hash
283
+ # - named_captures -> hash
188
284
  # -->
189
- # Returns a Hash using named capture.
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
- # A key of the hash is a name of the named captures. A value of the hash is a
192
- # string of last successful capture of corresponding group.
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
- # - mtch.names -> [name1, name2, ...]
308
+ # - names -> array_of_names
211
309
  # -->
212
- # Returns a list of names of captures as an array of strings. This is the same
213
- # as mtch.regexp.names.
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
- # /(?<foo>.)(?<bar>.)(?<baz>.)/.match("hoge").names
216
- # #=> ["foo", "bar", "baz"]
320
+ # Equivalent to:
217
321
  #
218
- # m = /(?<x>.)(?<y>.)?/.match("a") #=> #<MatchData "a" x:"a" y:nil>
219
- # m.names #=> ["x", "y"]
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
- # - mtch.match(n) -> string or nil
329
+ # - match(n) -> string or nil
330
+ # - match(name) -> string or nil
226
331
  # -->
227
- # Returns the captured substring corresponding to the argument. *n* can be a
228
- # string or symbol to reference a named capture.
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
- # m.match(0) #=> "HX1138"
232
- # m.match(4) #=> "8"
233
- # m.match(5) #=> nil
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
- # m.match(:foo) #=> "h"
237
- # m.match(:bar) #=> "ge"
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
- # - mtch.match_length(n) -> array
355
+ # - match_length(n) -> integer or nil
356
+ # - match_length(name) -> integer or nil
244
357
  # -->
245
- # Returns the length of the captured substring corresponding to the argument.
246
- # *n* can be a string or symbol to reference a named capture.
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
- # m.match_length(0) #=> 6
250
- # m.match_length(4) #=> 1
251
- # m.match_length(5) #=> nil
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
- # m.match_length(:foo) #=> 1
255
- # m.match_length(:bar) #=> 2
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
- # - mtch.offset(n) -> array
382
+ # - offset(n) -> [start_offset, end_offset]
383
+ # - offset(name) -> [start_offset, end_offset]
262
384
  # -->
263
- # Returns a two-element array containing the beginning and ending offsets of the
264
- # *n*th match. *n* can be a string or symbol to reference a named capture.
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
- # m.offset(0) #=> [1, 7]
268
- # m.offset(4) #=> [6, 7]
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
- # p m.offset(:foo) #=> [0, 1]
272
- # p m.offset(:bar) #=> [2, 3]
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
- # - mtch.post_match -> str
421
+ # - post_match -> str
279
422
  # -->
280
- # Returns the portion of the original string after the current match. Equivalent
281
- # to the special variable `$'`.
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
- # m.post_match #=> ": The Movie"
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
- # - mtch.pre_match -> str
438
+ # - pre_match -> string
291
439
  # -->
292
- # Returns the portion of the original string before the current match.
293
- # Equivalent to the special variable `$``.
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
- # m.pre_match #=> "T"
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
- # - mtch.regexp -> regexp
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 #=> /a.*b/
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
- # - mtch.length -> integer
314
- # - mtch.size -> integer
466
+ # - size -> integer
315
467
  # -->
316
- # Returns the number of elements in the match array.
468
+ # Returns size of the match array:
317
469
  #
318
470
  # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
319
- # m.length #=> 5
320
- # m.size #=> 5
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
- # - mtch.string -> str
480
+ # - string -> string
327
481
  # -->
328
- # Returns a frozen copy of the string passed in to `match`.
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
- # m.string #=> "THX1138."
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
- # - mtch.to_a -> anArray
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
- # m.to_a #=> ["HX1138", "H", "X", "113", "8"]
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
- # all,f1,f2,f3 = * /(.)(.)(\d+)(\d)/.match("THX1138.")
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
- # - mtch.to_s -> str
507
+ # - to_s -> string
359
508
  # -->
360
- # Returns the entire matched string.
509
+ # Returns the matched string:
361
510
  #
362
511
  # m = /(.)(.)(\d+)(\d)/.match("THX1138.")
363
- # m.to_s #=> "HX1138"
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
- # - mtch.values_at(index, ...) -> array
525
+ # - values_at(*indexes) -> array
370
526
  # -->
371
- # Uses each *index* to access the matching values, returning an array of the
372
- # corresponding matches.
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
- # m.to_a #=> ["HX1138", "H", "X", "113", "8"]
376
- # m.values_at(0, 2, -2) #=> ["HX1138", "X", "113"]
377
- # m.values_at(1..2, -1) #=> ["H", "X", "8"]
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
- # m.to_a #=> ["1 + 2", "1", "+", "2"]
381
- # m.values_at(:a, :b, :op) #=> ["1", "2", "+"]
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