rbs 3.3.2 → 3.4.0
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 -5
- data/.github/workflows/ruby.yml +7 -8
- data/.github/workflows/typecheck.yml +37 -0
- data/CHANGELOG.md +65 -0
- data/Gemfile +1 -1
- data/Gemfile.lock +11 -11
- data/README.md +1 -0
- data/Rakefile +2 -2
- data/Steepfile +2 -2
- data/core/array.rbs +19 -49
- data/core/basic_object.rbs +2 -2
- data/core/comparable.rbs +17 -8
- data/core/complex.rbs +82 -43
- data/core/data.rbs +2 -4
- data/core/dir.rbs +635 -295
- data/core/enumerable.rbs +11 -18
- data/core/enumerator.rbs +37 -31
- data/core/errors.rbs +4 -0
- data/core/false_class.rbs +34 -15
- data/core/fiber.rbs +23 -0
- data/core/file.rbs +329 -120
- data/core/float.rbs +17 -32
- data/core/gc.rbs +17 -11
- data/core/hash.rbs +22 -44
- data/core/integer.rbs +82 -113
- data/core/io/buffer.rbs +90 -47
- data/core/io.rbs +54 -121
- data/core/kernel.rbs +442 -489
- data/core/match_data.rbs +55 -56
- data/core/module.rbs +45 -1
- data/core/nil_class.rbs +98 -35
- data/core/numeric.rbs +22 -32
- data/core/object_space/weak_key_map.rbs +102 -0
- data/core/process.rbs +1242 -655
- data/core/ractor.rbs +139 -120
- data/core/range.rbs +100 -4
- data/core/rational.rbs +0 -4
- data/core/rbs/unnamed/argf.rbs +16 -8
- data/core/rbs/unnamed/env_class.rbs +0 -24
- data/core/refinement.rbs +8 -0
- data/core/regexp.rbs +1149 -598
- data/core/ruby_vm.rbs +126 -12
- data/core/rubygems/platform.rbs +9 -0
- data/core/rubygems/rubygems.rbs +1 -1
- data/core/rubygems/version.rbs +5 -1
- data/core/set.rbs +20 -22
- data/core/signal.rbs +4 -4
- data/core/string.rbs +283 -230
- data/core/string_io.rbs +2 -14
- data/core/struct.rbs +404 -24
- data/core/symbol.rbs +1 -19
- data/core/thread.rbs +29 -12
- data/core/time.rbs +227 -104
- data/core/trace_point.rbs +2 -5
- data/core/true_class.rbs +54 -21
- data/core/warning.rbs +14 -11
- data/docs/data_and_struct.md +29 -0
- data/docs/gem.md +58 -0
- data/docs/syntax.md +3 -5
- data/docs/tools.md +1 -0
- data/ext/rbs_extension/lexer.c +643 -559
- data/ext/rbs_extension/lexer.re +5 -1
- data/ext/rbs_extension/parser.c +12 -3
- data/ext/rbs_extension/unescape.c +7 -47
- data/lib/rbs/cli/diff.rb +4 -1
- data/lib/rbs/cli/validate.rb +280 -0
- data/lib/rbs/cli.rb +2 -194
- data/lib/rbs/collection/config.rb +5 -6
- data/lib/rbs/collection/sources/git.rb +1 -1
- data/lib/rbs/collection.rb +1 -0
- data/lib/rbs/diff.rb +7 -4
- data/lib/rbs/errors.rb +11 -0
- data/lib/rbs/test/errors.rb +10 -2
- data/lib/rbs/test/guaranteed.rb +2 -3
- data/lib/rbs/test/type_check.rb +15 -10
- data/lib/rbs/test.rb +3 -3
- data/lib/rbs/types.rb +29 -0
- data/lib/rbs/unit_test/convertibles.rb +176 -0
- data/lib/rbs/unit_test/spy.rb +136 -0
- data/lib/rbs/unit_test/type_assertions.rb +341 -0
- data/lib/rbs/unit_test/with_aliases.rb +143 -0
- data/lib/rbs/unit_test.rb +6 -0
- data/lib/rbs/version.rb +1 -1
- data/sig/cli/validate.rbs +43 -0
- data/sig/diff.rbs +3 -1
- data/sig/errors.rbs +8 -0
- data/sig/rbs.rbs +1 -1
- data/sig/test/errors.rbs +52 -0
- data/sig/test/guranteed.rbs +9 -0
- data/sig/test/type_check.rbs +19 -0
- data/sig/test.rbs +82 -0
- data/sig/types.rbs +6 -1
- data/sig/unit_test/convertibles.rbs +154 -0
- data/sig/unit_test/spy.rbs +28 -0
- data/sig/unit_test/type_assertions.rbs +194 -0
- data/sig/unit_test/with_aliases.rbs +136 -0
- data/stdlib/base64/0/base64.rbs +307 -45
- data/stdlib/bigdecimal/0/big_decimal.rbs +35 -15
- data/stdlib/coverage/0/coverage.rbs +2 -2
- data/stdlib/csv/0/csv.rbs +25 -55
- data/stdlib/date/0/date.rbs +1 -43
- data/stdlib/date/0/date_time.rbs +1 -13
- data/stdlib/delegate/0/delegator.rbs +186 -0
- data/stdlib/delegate/0/kernel.rbs +47 -0
- data/stdlib/delegate/0/simple_delegator.rbs +98 -0
- data/stdlib/did_you_mean/0/did_you_mean.rbs +1 -1
- data/stdlib/erb/0/erb.rbs +2 -2
- data/stdlib/fileutils/0/fileutils.rbs +0 -19
- data/stdlib/io-console/0/io-console.rbs +12 -1
- data/stdlib/ipaddr/0/ipaddr.rbs +2 -1
- data/stdlib/json/0/json.rbs +320 -81
- data/stdlib/logger/0/logger.rbs +9 -5
- data/stdlib/minitest/0/minitest/test/lifecycle_hooks.rbs +6 -6
- data/stdlib/monitor/0/monitor.rbs +78 -0
- data/stdlib/net-http/0/net-http.rbs +1880 -543
- data/stdlib/objspace/0/objspace.rbs +19 -13
- data/stdlib/openssl/0/openssl.rbs +508 -127
- data/stdlib/optparse/0/optparse.rbs +25 -11
- data/stdlib/pathname/0/pathname.rbs +1 -1
- data/stdlib/pp/0/pp.rbs +2 -5
- data/stdlib/prettyprint/0/prettyprint.rbs +2 -2
- data/stdlib/pstore/0/pstore.rbs +2 -4
- data/stdlib/rdoc/0/comment.rbs +1 -2
- data/stdlib/resolv/0/resolv.rbs +4 -2
- data/stdlib/socket/0/socket.rbs +2 -2
- data/stdlib/socket/0/unix_socket.rbs +2 -2
- data/stdlib/strscan/0/string_scanner.rbs +3 -2
- data/stdlib/tempfile/0/tempfile.rbs +1 -1
- data/stdlib/uri/0/common.rbs +245 -123
- metadata +24 -4
- data/lib/rbs/test/spy.rb +0 -6
data/core/string_io.rbs
CHANGED
|
@@ -131,8 +131,6 @@ class StringIO
|
|
|
131
131
|
# Calls the block with each remaining line read from the stream; does nothing if
|
|
132
132
|
# already at end-of-file; returns `self`. See [Line IO](rdoc-ref:IO@Line+IO).
|
|
133
133
|
#
|
|
134
|
-
# StringIO#each is an alias for StringIO#each_line.
|
|
135
|
-
#
|
|
136
134
|
def each: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self
|
|
137
135
|
| (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self]
|
|
138
136
|
|
|
@@ -177,12 +175,10 @@ class StringIO
|
|
|
177
175
|
# - eof? -> true or false
|
|
178
176
|
# -->
|
|
179
177
|
# Returns `true` if positioned at end-of-stream, `false` otherwise; see
|
|
180
|
-
# [Position](rdoc-ref:
|
|
178
|
+
# [Position](rdoc-ref:IO@Position).
|
|
181
179
|
#
|
|
182
180
|
# Raises IOError if the stream is not opened for reading.
|
|
183
181
|
#
|
|
184
|
-
# StreamIO#eof is an alias for StreamIO#eof?.
|
|
185
|
-
#
|
|
186
182
|
def eof: () -> bool
|
|
187
183
|
|
|
188
184
|
# <!--
|
|
@@ -304,8 +300,6 @@ class StringIO
|
|
|
304
300
|
# -->
|
|
305
301
|
# Returns the current position (in bytes); see [Position](rdoc-ref:IO@Position).
|
|
306
302
|
#
|
|
307
|
-
# StringIO#tell is an alias for StringIO#pos.
|
|
308
|
-
#
|
|
309
303
|
def pos: () -> Integer
|
|
310
304
|
|
|
311
305
|
# <!--
|
|
@@ -491,8 +485,6 @@ class StringIO
|
|
|
491
485
|
# -->
|
|
492
486
|
# Returns the current position (in bytes); see [Position](rdoc-ref:IO@Position).
|
|
493
487
|
#
|
|
494
|
-
# StringIO#tell is an alias for StringIO#pos.
|
|
495
|
-
#
|
|
496
488
|
def tell: () -> Integer
|
|
497
489
|
|
|
498
490
|
# <!--
|
|
@@ -557,19 +549,15 @@ class StringIO
|
|
|
557
549
|
# Calls the block with each remaining line read from the stream; does nothing if
|
|
558
550
|
# already at end-of-file; returns `self`. See [Line IO](rdoc-ref:IO@Line+IO).
|
|
559
551
|
#
|
|
560
|
-
# StringIO#each is an alias for StringIO#each_line.
|
|
561
|
-
#
|
|
562
552
|
def each_line: (?String sep, ?Integer limit, ?chomp: boolish) { (String) -> untyped } -> self
|
|
563
553
|
| (?String sep, ?Integer limit, ?chomp: boolish) -> ::Enumerator[String, self]
|
|
564
554
|
|
|
565
555
|
# <!-- rdoc-file=ext/stringio/stringio.c -->
|
|
566
556
|
# Returns `true` if positioned at end-of-stream, `false` otherwise; see
|
|
567
|
-
# [Position](rdoc-ref:
|
|
557
|
+
# [Position](rdoc-ref:IO@Position).
|
|
568
558
|
#
|
|
569
559
|
# Raises IOError if the stream is not opened for reading.
|
|
570
560
|
#
|
|
571
|
-
# StreamIO#eof is an alias for StreamIO#eof?.
|
|
572
|
-
#
|
|
573
561
|
def eof?: () -> bool
|
|
574
562
|
|
|
575
563
|
# This is a deprecated alias for #each_line.
|
data/core/struct.rbs
CHANGED
|
@@ -112,15 +112,18 @@
|
|
|
112
112
|
# * #inspect, #to_s: Returns a string representation of `self`.
|
|
113
113
|
# * #to_h: Returns a hash of the member name/value pairs in `self`.
|
|
114
114
|
#
|
|
115
|
-
class Struct[Elem]
|
|
116
|
-
include Enumerable[Elem
|
|
115
|
+
class Struct[Elem]
|
|
116
|
+
include Enumerable[Elem]
|
|
117
117
|
|
|
118
|
-
|
|
118
|
+
# The types that can be used when "indexing" into a `Struct` via `[]`, `[]=`, `dig`, and
|
|
119
|
+
# `deconstruct_keys`.
|
|
120
|
+
#
|
|
121
|
+
type index = String | Symbol | int
|
|
119
122
|
|
|
120
123
|
# <!--
|
|
121
124
|
# rdoc-file=struct.c
|
|
122
|
-
# - Struct.new(*member_names, keyword_init:
|
|
123
|
-
# - Struct.new(class_name, *member_names, keyword_init:
|
|
125
|
+
# - Struct.new(*member_names, keyword_init: nil){|Struct_subclass| ... } -> Struct_subclass
|
|
126
|
+
# - Struct.new(class_name, *member_names, keyword_init: nil){|Struct_subclass| ... } -> Struct_subclass
|
|
124
127
|
# - Struct_subclass.new(*member_names) -> Struct_subclass_instance
|
|
125
128
|
# - Struct_subclass.new(**member_names) -> Struct_subclass_instance
|
|
126
129
|
# -->
|
|
@@ -203,8 +206,6 @@ class Struct[Elem] < Object
|
|
|
203
206
|
# Foo.new(foo: 0, bar: 1, baz: 2)
|
|
204
207
|
# # Raises ArgumentError: unknown keywords: baz
|
|
205
208
|
#
|
|
206
|
-
# Method `::[]` is an alias for method `::new`.
|
|
207
|
-
#
|
|
208
209
|
# * Method `:inspect` returns a string representation of the subclass:
|
|
209
210
|
#
|
|
210
211
|
# Foo.inspect
|
|
@@ -243,7 +244,192 @@ class Struct[Elem] < Object
|
|
|
243
244
|
# Any.new(1, 2)
|
|
244
245
|
# # => #<struct Any foo=1, bar=2>
|
|
245
246
|
#
|
|
246
|
-
def
|
|
247
|
+
def self.new: (string? classname, *interned fields, ?keyword_init: boolish?) ?{ (singleton(Struct)) [self: singleton(Struct)] -> void } -> untyped
|
|
248
|
+
| (Symbol field1, *interned fields, ?keyword_init: boolish?) ?{ (singleton(Struct)) [self: singleton(Struct)] -> void } -> untyped
|
|
249
|
+
|
|
250
|
+
# <!--
|
|
251
|
+
# rdoc-file=struct.c
|
|
252
|
+
# - StructClass::members -> array_of_symbols
|
|
253
|
+
# -->
|
|
254
|
+
# Returns the member names of the Struct descendant as an array:
|
|
255
|
+
#
|
|
256
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
257
|
+
# Customer.members # => [:name, :address, :zip]
|
|
258
|
+
#
|
|
259
|
+
def self.members: () -> Array[Symbol]
|
|
260
|
+
|
|
261
|
+
# <!--
|
|
262
|
+
# rdoc-file=struct.c
|
|
263
|
+
# - StructClass::keyword_init? -> true or falsy value
|
|
264
|
+
# -->
|
|
265
|
+
# Returns `true` if the class was initialized with `keyword_init: true`.
|
|
266
|
+
# Otherwise returns `nil` or `false`.
|
|
267
|
+
#
|
|
268
|
+
# Examples:
|
|
269
|
+
# Foo = Struct.new(:a)
|
|
270
|
+
# Foo.keyword_init? # => nil
|
|
271
|
+
# Bar = Struct.new(:a, keyword_init: true)
|
|
272
|
+
# Bar.keyword_init? # => true
|
|
273
|
+
# Baz = Struct.new(:a, keyword_init: false)
|
|
274
|
+
# Baz.keyword_init? # => false
|
|
275
|
+
#
|
|
276
|
+
def self.keyword_init?: () -> bool?
|
|
277
|
+
|
|
278
|
+
# <!--
|
|
279
|
+
# rdoc-file=struct.c
|
|
280
|
+
# - self == other -> true or false
|
|
281
|
+
# -->
|
|
282
|
+
# Returns `true` if and only if the following are true; otherwise returns
|
|
283
|
+
# `false`:
|
|
284
|
+
#
|
|
285
|
+
# * `other.class == self.class`.
|
|
286
|
+
# * For each member name `name`, `other.name == self.name`.
|
|
287
|
+
#
|
|
288
|
+
#
|
|
289
|
+
# Examples:
|
|
290
|
+
#
|
|
291
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
292
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
293
|
+
# joe_jr = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
294
|
+
# joe_jr == joe # => true
|
|
295
|
+
# joe_jr[:name] = 'Joe Smith, Jr.'
|
|
296
|
+
# # => "Joe Smith, Jr."
|
|
297
|
+
# joe_jr == joe # => false
|
|
298
|
+
#
|
|
299
|
+
def ==: (untyped other) -> bool
|
|
300
|
+
|
|
301
|
+
# <!--
|
|
302
|
+
# rdoc-file=struct.c
|
|
303
|
+
# - eql?(other) -> true or false
|
|
304
|
+
# -->
|
|
305
|
+
# Returns `true` if and only if the following are true; otherwise returns
|
|
306
|
+
# `false`:
|
|
307
|
+
#
|
|
308
|
+
# * `other.class == self.class`.
|
|
309
|
+
# * For each member name `name`, `other.name.eql?(self.name)`.
|
|
310
|
+
#
|
|
311
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
312
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
313
|
+
# joe_jr = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
314
|
+
# joe_jr.eql?(joe) # => true
|
|
315
|
+
# joe_jr[:name] = 'Joe Smith, Jr.'
|
|
316
|
+
# joe_jr.eql?(joe) # => false
|
|
317
|
+
#
|
|
318
|
+
#
|
|
319
|
+
# Related: Object#==.
|
|
320
|
+
#
|
|
321
|
+
def eql?: (untyped other) -> bool
|
|
322
|
+
|
|
323
|
+
# <!--
|
|
324
|
+
# rdoc-file=struct.c
|
|
325
|
+
# - hash -> integer
|
|
326
|
+
# -->
|
|
327
|
+
# Returns the integer hash value for `self`.
|
|
328
|
+
#
|
|
329
|
+
# Two structs of the same class and with the same content will have the same
|
|
330
|
+
# hash code (and will compare using Struct#eql?):
|
|
331
|
+
#
|
|
332
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
333
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
334
|
+
# joe_jr = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
335
|
+
# joe.hash == joe_jr.hash # => true
|
|
336
|
+
# joe_jr[:name] = 'Joe Smith, Jr.'
|
|
337
|
+
# joe.hash == joe_jr.hash # => false
|
|
338
|
+
#
|
|
339
|
+
# Related: Object#hash.
|
|
340
|
+
#
|
|
341
|
+
def hash: () -> Integer
|
|
342
|
+
|
|
343
|
+
# <!--
|
|
344
|
+
# rdoc-file=struct.c
|
|
345
|
+
# - inspect -> string
|
|
346
|
+
# -->
|
|
347
|
+
# Returns a string representation of `self`:
|
|
348
|
+
#
|
|
349
|
+
# Customer = Struct.new(:name, :address, :zip) # => Customer
|
|
350
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
351
|
+
# joe.inspect # => "#<struct Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"
|
|
352
|
+
#
|
|
353
|
+
def inspect: () -> String
|
|
354
|
+
|
|
355
|
+
# <!-- rdoc-file=struct.c -->
|
|
356
|
+
# Returns a string representation of `self`:
|
|
357
|
+
#
|
|
358
|
+
# Customer = Struct.new(:name, :address, :zip) # => Customer
|
|
359
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
360
|
+
# joe.inspect # => "#<struct Customer name=\"Joe Smith\", address=\"123 Maple, Anytown NC\", zip=12345>"
|
|
361
|
+
#
|
|
362
|
+
alias to_s inspect
|
|
363
|
+
|
|
364
|
+
# <!--
|
|
365
|
+
# rdoc-file=struct.c
|
|
366
|
+
# - to_a -> array
|
|
367
|
+
# -->
|
|
368
|
+
# Returns the values in `self` as an array:
|
|
369
|
+
#
|
|
370
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
371
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
372
|
+
# joe.to_a # => ["Joe Smith", "123 Maple, Anytown NC", 12345]
|
|
373
|
+
#
|
|
374
|
+
# Related: #members.
|
|
375
|
+
#
|
|
376
|
+
def to_a: () -> Array[Elem]
|
|
377
|
+
|
|
378
|
+
# <!--
|
|
379
|
+
# rdoc-file=struct.c
|
|
380
|
+
# - to_h -> hash
|
|
381
|
+
# - to_h {|name, value| ... } -> hash
|
|
382
|
+
# -->
|
|
383
|
+
# Returns a hash containing the name and value for each member:
|
|
384
|
+
#
|
|
385
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
386
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
387
|
+
# h = joe.to_h
|
|
388
|
+
# h # => {:name=>"Joe Smith", :address=>"123 Maple, Anytown NC", :zip=>12345}
|
|
389
|
+
#
|
|
390
|
+
# If a block is given, it is called with each name/value pair; the block should
|
|
391
|
+
# return a 2-element array whose elements will become a key/value pair in the
|
|
392
|
+
# returned hash:
|
|
393
|
+
#
|
|
394
|
+
# h = joe.to_h{|name, value| [name.upcase, value.to_s.upcase]}
|
|
395
|
+
# h # => {:NAME=>"JOE SMITH", :ADDRESS=>"123 MAPLE, ANYTOWN NC", :ZIP=>"12345"}
|
|
396
|
+
#
|
|
397
|
+
# Raises ArgumentError if the block returns an inappropriate value.
|
|
398
|
+
#
|
|
399
|
+
def to_h: () -> Hash[Symbol, Elem]
|
|
400
|
+
| [K, V] () { (Symbol key, Elem value) -> [K, V] } -> Hash[K, V]
|
|
401
|
+
|
|
402
|
+
# <!-- rdoc-file=struct.c -->
|
|
403
|
+
# Returns the values in `self` as an array:
|
|
404
|
+
#
|
|
405
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
406
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
407
|
+
# joe.to_a # => ["Joe Smith", "123 Maple, Anytown NC", 12345]
|
|
408
|
+
#
|
|
409
|
+
# Related: #members.
|
|
410
|
+
#
|
|
411
|
+
alias values to_a
|
|
412
|
+
|
|
413
|
+
# <!--
|
|
414
|
+
# rdoc-file=struct.c
|
|
415
|
+
# - size -> integer
|
|
416
|
+
# -->
|
|
417
|
+
# Returns the number of members.
|
|
418
|
+
#
|
|
419
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
420
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
421
|
+
# joe.size #=> 3
|
|
422
|
+
#
|
|
423
|
+
def size: () -> Integer
|
|
424
|
+
|
|
425
|
+
# <!-- rdoc-file=struct.c -->
|
|
426
|
+
# Returns the number of members.
|
|
427
|
+
#
|
|
428
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
429
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
430
|
+
# joe.size #=> 3
|
|
431
|
+
#
|
|
432
|
+
alias length size
|
|
247
433
|
|
|
248
434
|
# <!--
|
|
249
435
|
# rdoc-file=struct.c
|
|
@@ -266,34 +452,228 @@ class Struct[Elem] < Object
|
|
|
266
452
|
#
|
|
267
453
|
# Related: #each_pair.
|
|
268
454
|
#
|
|
269
|
-
def each: () ->
|
|
270
|
-
| () { (Elem
|
|
455
|
+
def each: () -> Enumerator[Elem, self]
|
|
456
|
+
| () { (Elem value) -> void } -> self
|
|
271
457
|
|
|
272
458
|
# <!--
|
|
273
459
|
# rdoc-file=struct.c
|
|
274
|
-
# -
|
|
460
|
+
# - each_pair {|(name, value)| ... } -> self
|
|
461
|
+
# - each_pair -> enumerator
|
|
275
462
|
# -->
|
|
276
|
-
#
|
|
463
|
+
# Calls the given block with each member name/value pair; returns `self`:
|
|
464
|
+
#
|
|
465
|
+
# Customer = Struct.new(:name, :address, :zip) # => Customer
|
|
466
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
467
|
+
# joe.each_pair {|(name, value)| p "#{name} => #{value}" }
|
|
468
|
+
#
|
|
469
|
+
# Output:
|
|
470
|
+
#
|
|
471
|
+
# "name => Joe Smith"
|
|
472
|
+
# "address => 123 Maple, Anytown NC"
|
|
473
|
+
# "zip => 12345"
|
|
474
|
+
#
|
|
475
|
+
# Returns an Enumerator if no block is given.
|
|
476
|
+
#
|
|
477
|
+
# Related: #each.
|
|
478
|
+
#
|
|
479
|
+
def each_pair: () -> Enumerator[[Symbol, Elem], self]
|
|
480
|
+
| () { ([Symbol, Elem] key_value) -> void } -> self
|
|
481
|
+
|
|
482
|
+
# <!--
|
|
483
|
+
# rdoc-file=struct.c
|
|
484
|
+
# - struct[name] -> object
|
|
485
|
+
# - struct[n] -> object
|
|
486
|
+
# -->
|
|
487
|
+
# Returns a value from `self`.
|
|
488
|
+
#
|
|
489
|
+
# With symbol or string argument `name` given, returns the value for the named
|
|
490
|
+
# member:
|
|
277
491
|
#
|
|
278
492
|
# Customer = Struct.new(:name, :address, :zip)
|
|
279
|
-
# Customer.
|
|
493
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
494
|
+
# joe[:zip] # => 12345
|
|
495
|
+
#
|
|
496
|
+
# Raises NameError if `name` is not the name of a member.
|
|
497
|
+
#
|
|
498
|
+
# With integer argument `n` given, returns `self.values[n]` if `n` is in range;
|
|
499
|
+
# see Array@Array+Indexes:
|
|
500
|
+
#
|
|
501
|
+
# joe[2] # => 12345
|
|
502
|
+
# joe[-2] # => "123 Maple, Anytown NC"
|
|
503
|
+
#
|
|
504
|
+
# Raises IndexError if `n` is out of range.
|
|
280
505
|
#
|
|
281
|
-
def
|
|
506
|
+
def []: (index name_or_position) -> Elem
|
|
282
507
|
|
|
283
508
|
# <!--
|
|
284
509
|
# rdoc-file=struct.c
|
|
285
|
-
# -
|
|
510
|
+
# - struct[name] = value -> value
|
|
511
|
+
# - struct[n] = value -> value
|
|
286
512
|
# -->
|
|
287
|
-
#
|
|
288
|
-
#
|
|
513
|
+
# Assigns a value to a member.
|
|
514
|
+
#
|
|
515
|
+
# With symbol or string argument `name` given, assigns the given `value` to the
|
|
516
|
+
# named member; returns `value`:
|
|
517
|
+
#
|
|
518
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
519
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
520
|
+
# joe[:zip] = 54321 # => 54321
|
|
521
|
+
# joe # => #<struct Customer name="Joe Smith", address="123 Maple, Anytown NC", zip=54321>
|
|
522
|
+
#
|
|
523
|
+
# Raises NameError if `name` is not the name of a member.
|
|
524
|
+
#
|
|
525
|
+
# With integer argument `n` given, assigns the given `value` to the `n`-th
|
|
526
|
+
# member if `n` is in range; see Array@Array+Indexes:
|
|
527
|
+
#
|
|
528
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
529
|
+
# joe[2] = 54321 # => 54321
|
|
530
|
+
# joe[-3] = 'Joseph Smith' # => "Joseph Smith"
|
|
531
|
+
# joe # => #<struct Customer name="Joseph Smith", address="123 Maple, Anytown NC", zip=54321>
|
|
532
|
+
#
|
|
533
|
+
# Raises IndexError if `n` is out of range.
|
|
534
|
+
#
|
|
535
|
+
def []=: (index name_or_position, Elem value) -> Elem
|
|
536
|
+
|
|
537
|
+
# <!--
|
|
538
|
+
# rdoc-file=struct.c
|
|
539
|
+
# - select {|value| ... } -> array
|
|
540
|
+
# - select -> enumerator
|
|
541
|
+
# -->
|
|
542
|
+
# With a block given, returns an array of values from `self` for which the block
|
|
543
|
+
# returns a truthy value:
|
|
544
|
+
#
|
|
545
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
546
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
547
|
+
# a = joe.select {|value| value.is_a?(String) }
|
|
548
|
+
# a # => ["Joe Smith", "123 Maple, Anytown NC"]
|
|
549
|
+
# a = joe.select {|value| value.is_a?(Integer) }
|
|
550
|
+
# a # => [12345]
|
|
551
|
+
#
|
|
552
|
+
# With no block given, returns an Enumerator.
|
|
553
|
+
#
|
|
554
|
+
def select: () -> Enumerator[Elem, Array[Elem]]
|
|
555
|
+
| () { (Elem value) -> boolish } -> Array[Elem]
|
|
556
|
+
|
|
557
|
+
# <!-- rdoc-file=struct.c -->
|
|
558
|
+
# With a block given, returns an array of values from `self` for which the block
|
|
559
|
+
# returns a truthy value:
|
|
560
|
+
#
|
|
561
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
562
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
563
|
+
# a = joe.select {|value| value.is_a?(String) }
|
|
564
|
+
# a # => ["Joe Smith", "123 Maple, Anytown NC"]
|
|
565
|
+
# a = joe.select {|value| value.is_a?(Integer) }
|
|
566
|
+
# a # => [12345]
|
|
567
|
+
#
|
|
568
|
+
# With no block given, returns an Enumerator.
|
|
569
|
+
#
|
|
570
|
+
alias filter select
|
|
571
|
+
|
|
572
|
+
# <!--
|
|
573
|
+
# rdoc-file=struct.c
|
|
574
|
+
# - values_at(*integers) -> array
|
|
575
|
+
# - values_at(integer_range) -> array
|
|
576
|
+
# -->
|
|
577
|
+
# Returns an array of values from `self`.
|
|
578
|
+
#
|
|
579
|
+
# With integer arguments `integers` given, returns an array containing each
|
|
580
|
+
# value given by one of `integers`:
|
|
581
|
+
#
|
|
582
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
583
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
584
|
+
# joe.values_at(0, 2) # => ["Joe Smith", 12345]
|
|
585
|
+
# joe.values_at(2, 0) # => [12345, "Joe Smith"]
|
|
586
|
+
# joe.values_at(2, 1, 0) # => [12345, "123 Maple, Anytown NC", "Joe Smith"]
|
|
587
|
+
# joe.values_at(0, -3) # => ["Joe Smith", "Joe Smith"]
|
|
588
|
+
#
|
|
589
|
+
# Raises IndexError if any of `integers` is out of range; see
|
|
590
|
+
# Array@Array+Indexes.
|
|
591
|
+
#
|
|
592
|
+
# With integer range argument `integer_range` given, returns an array containing
|
|
593
|
+
# each value given by the elements of the range; fills with `nil` values for
|
|
594
|
+
# range elements larger than the structure:
|
|
595
|
+
#
|
|
596
|
+
# joe.values_at(0..2)
|
|
597
|
+
# # => ["Joe Smith", "123 Maple, Anytown NC", 12345]
|
|
598
|
+
# joe.values_at(-3..-1)
|
|
599
|
+
# # => ["Joe Smith", "123 Maple, Anytown NC", 12345]
|
|
600
|
+
# joe.values_at(1..4) # => ["123 Maple, Anytown NC", 12345, nil, nil]
|
|
601
|
+
#
|
|
602
|
+
# Raises RangeError if any element of the range is negative and out of range;
|
|
603
|
+
# see Array@Array+Indexes.
|
|
604
|
+
#
|
|
605
|
+
def values_at: (*int | range[int?] positions) -> Array[Elem]
|
|
606
|
+
|
|
607
|
+
# <!--
|
|
608
|
+
# rdoc-file=struct.c
|
|
609
|
+
# - members -> array_of_symbols
|
|
610
|
+
# -->
|
|
611
|
+
# Returns the member names from `self` as an array:
|
|
612
|
+
#
|
|
613
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
614
|
+
# Customer.new.members # => [:name, :address, :zip]
|
|
615
|
+
#
|
|
616
|
+
# Related: #to_a.
|
|
617
|
+
#
|
|
618
|
+
def members: () -> Array[Symbol]
|
|
619
|
+
|
|
620
|
+
# <!--
|
|
621
|
+
# rdoc-file=struct.c
|
|
622
|
+
# - dig(name, *identifiers) -> object
|
|
623
|
+
# - dig(n, *identifiers) -> object
|
|
624
|
+
# -->
|
|
625
|
+
# Finds and returns an object among nested objects. The nested objects may be
|
|
626
|
+
# instances of various classes. See [Dig Methods](rdoc-ref:dig_methods.rdoc).
|
|
627
|
+
#
|
|
628
|
+
# Given symbol or string argument `name`, returns the object that is specified
|
|
629
|
+
# by `name` and `identifiers`:
|
|
289
630
|
#
|
|
290
|
-
# Examples:
|
|
291
631
|
# Foo = Struct.new(:a)
|
|
292
|
-
# Foo.
|
|
293
|
-
#
|
|
294
|
-
#
|
|
295
|
-
#
|
|
296
|
-
#
|
|
632
|
+
# f = Foo.new(Foo.new({b: [1, 2, 3]}))
|
|
633
|
+
# f.dig(:a) # => #<struct Foo a={:b=>[1, 2, 3]}>
|
|
634
|
+
# f.dig(:a, :a) # => {:b=>[1, 2, 3]}
|
|
635
|
+
# f.dig(:a, :a, :b) # => [1, 2, 3]
|
|
636
|
+
# f.dig(:a, :a, :b, 0) # => 1
|
|
637
|
+
# f.dig(:b, 0) # => nil
|
|
638
|
+
#
|
|
639
|
+
# Given integer argument `n`, returns the object that is specified by `n` and
|
|
640
|
+
# `identifiers`:
|
|
641
|
+
#
|
|
642
|
+
# f.dig(0) # => #<struct Foo a={:b=>[1, 2, 3]}>
|
|
643
|
+
# f.dig(0, 0) # => {:b=>[1, 2, 3]}
|
|
644
|
+
# f.dig(0, 0, :b) # => [1, 2, 3]
|
|
645
|
+
# f.dig(0, 0, :b, 0) # => 1
|
|
646
|
+
# f.dig(:b, 0) # => nil
|
|
647
|
+
#
|
|
648
|
+
def dig: (index name_or_position) -> Elem
|
|
649
|
+
| (index name_or_position, untyped, *untyped) -> untyped
|
|
650
|
+
|
|
651
|
+
# <!-- rdoc-file=struct.c -->
|
|
652
|
+
# Returns the values in `self` as an array:
|
|
653
|
+
#
|
|
654
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
655
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
656
|
+
# joe.to_a # => ["Joe Smith", "123 Maple, Anytown NC", 12345]
|
|
657
|
+
#
|
|
658
|
+
# Related: #members.
|
|
659
|
+
#
|
|
660
|
+
alias deconstruct to_a
|
|
661
|
+
|
|
662
|
+
# <!--
|
|
663
|
+
# rdoc-file=struct.c
|
|
664
|
+
# - deconstruct_keys(array_of_names) -> hash
|
|
665
|
+
# -->
|
|
666
|
+
# Returns a hash of the name/value pairs for the given member names.
|
|
667
|
+
#
|
|
668
|
+
# Customer = Struct.new(:name, :address, :zip)
|
|
669
|
+
# joe = Customer.new("Joe Smith", "123 Maple, Anytown NC", 12345)
|
|
670
|
+
# h = joe.deconstruct_keys([:zip, :address])
|
|
671
|
+
# h # => {:zip=>12345, :address=>"123 Maple, Anytown NC"}
|
|
672
|
+
#
|
|
673
|
+
# Returns all names and values if `array_of_names` is `nil`:
|
|
674
|
+
#
|
|
675
|
+
# h = joe.deconstruct_keys(nil)
|
|
676
|
+
# h # => {:name=>"Joseph Smith, Jr.", :address=>"123 Maple, Anytown NC", :zip=>12345}
|
|
297
677
|
#
|
|
298
|
-
def
|
|
678
|
+
def deconstruct_keys: (Array[index & Hash::_Key]? indices) -> Hash[index & Hash::_Key, Elem]
|
|
299
679
|
end
|
data/core/symbol.rbs
CHANGED
|
@@ -161,15 +161,11 @@ class Symbol
|
|
|
161
161
|
# -->
|
|
162
162
|
# Returns `true` if `object` is the same object as `self`, `false` otherwise.
|
|
163
163
|
#
|
|
164
|
-
# Symbol#=== is an alias for Symbol#==.
|
|
165
|
-
#
|
|
166
164
|
def ==: (untyped obj) -> bool
|
|
167
165
|
|
|
168
166
|
# <!-- rdoc-file=string.c -->
|
|
169
167
|
# Returns `true` if `object` is the same object as `self`, `false` otherwise.
|
|
170
168
|
#
|
|
171
|
-
# Symbol#=== is an alias for Symbol#==.
|
|
172
|
-
#
|
|
173
169
|
def ===: (untyped obj) -> bool
|
|
174
170
|
|
|
175
171
|
# <!--
|
|
@@ -311,7 +307,7 @@ class Symbol
|
|
|
311
307
|
|
|
312
308
|
# <!--
|
|
313
309
|
# rdoc-file=string.c
|
|
314
|
-
# - end_with?(*
|
|
310
|
+
# - end_with?(*strings) -> true or false
|
|
315
311
|
# -->
|
|
316
312
|
# Equivalent to `self.to_s.end_with?`; see String#end_with?.
|
|
317
313
|
#
|
|
@@ -322,8 +318,6 @@ class Symbol
|
|
|
322
318
|
#
|
|
323
319
|
# :foo.to_s # => "foo"
|
|
324
320
|
#
|
|
325
|
-
# Symbol#id2name is an alias for Symbol#to_s.
|
|
326
|
-
#
|
|
327
321
|
# Related: Symbol#inspect, Symbol#name.
|
|
328
322
|
#
|
|
329
323
|
def id2name: () -> String
|
|
@@ -353,8 +347,6 @@ class Symbol
|
|
|
353
347
|
# -->
|
|
354
348
|
# Equivalent to `self.to_s.length`; see String#length.
|
|
355
349
|
#
|
|
356
|
-
# Symbol#size is an alias for Symbol#length.
|
|
357
|
-
#
|
|
358
350
|
def length: () -> Integer
|
|
359
351
|
|
|
360
352
|
# <!--
|
|
@@ -381,8 +373,6 @@ class Symbol
|
|
|
381
373
|
#
|
|
382
374
|
# :foo.succ # => :fop
|
|
383
375
|
#
|
|
384
|
-
# Symbol#next is an alias for Symbol#succ.
|
|
385
|
-
#
|
|
386
376
|
# Related: String#succ.
|
|
387
377
|
#
|
|
388
378
|
def next: () -> Symbol
|
|
@@ -390,8 +380,6 @@ class Symbol
|
|
|
390
380
|
# <!-- rdoc-file=string.c -->
|
|
391
381
|
# Equivalent to `self.to_s.length`; see String#length.
|
|
392
382
|
#
|
|
393
|
-
# Symbol#size is an alias for Symbol#length.
|
|
394
|
-
#
|
|
395
383
|
alias size length
|
|
396
384
|
|
|
397
385
|
# <!-- rdoc-file=string.c -->
|
|
@@ -415,8 +403,6 @@ class Symbol
|
|
|
415
403
|
#
|
|
416
404
|
# :foo.succ # => :fop
|
|
417
405
|
#
|
|
418
|
-
# Symbol#next is an alias for Symbol#succ.
|
|
419
|
-
#
|
|
420
406
|
# Related: String#succ.
|
|
421
407
|
#
|
|
422
408
|
alias succ next
|
|
@@ -456,8 +442,6 @@ class Symbol
|
|
|
456
442
|
#
|
|
457
443
|
# :foo.to_s # => "foo"
|
|
458
444
|
#
|
|
459
|
-
# Symbol#id2name is an alias for Symbol#to_s.
|
|
460
|
-
#
|
|
461
445
|
# Related: Symbol#inspect, Symbol#name.
|
|
462
446
|
#
|
|
463
447
|
alias to_s id2name
|
|
@@ -468,8 +452,6 @@ class Symbol
|
|
|
468
452
|
# -->
|
|
469
453
|
# Returns `self`.
|
|
470
454
|
#
|
|
471
|
-
# Symbol#intern is an alias for Symbol#to_sym.
|
|
472
|
-
#
|
|
473
455
|
# Related: String#to_sym.
|
|
474
456
|
#
|
|
475
457
|
alias to_sym intern
|
data/core/thread.rbs
CHANGED
|
@@ -991,9 +991,8 @@ class Thread < Object
|
|
|
991
991
|
# from prog.rb:2:in `new'
|
|
992
992
|
# from prog.rb:2
|
|
993
993
|
#
|
|
994
|
-
def
|
|
995
|
-
|
|
996
|
-
| (_Exception exception, ?untyped message, ?::Array[String] backtrace, ?cause: Exception?) -> bot
|
|
994
|
+
def raise: (?String message) -> nil
|
|
995
|
+
| (_Exception, ?_ToS message, ?Array[String] backtrace) -> nil
|
|
997
996
|
|
|
998
997
|
# <!--
|
|
999
998
|
# rdoc-file=thread.c
|
|
@@ -1438,7 +1437,7 @@ class Thread::ConditionVariable < Object
|
|
|
1438
1437
|
#
|
|
1439
1438
|
# Returns the slept result on `mutex`.
|
|
1440
1439
|
#
|
|
1441
|
-
def wait: (Thread::Mutex mutex, ?Integer | Float? timeout) ->
|
|
1440
|
+
def wait: (Thread::Mutex mutex, ?Integer | Float? timeout) -> Integer?
|
|
1442
1441
|
end
|
|
1443
1442
|
|
|
1444
1443
|
# <!-- rdoc-file=thread_sync.c -->
|
|
@@ -1521,8 +1520,8 @@ end
|
|
|
1521
1520
|
# exchanged safely between multiple threads. The Thread::Queue class implements
|
|
1522
1521
|
# all the required locking semantics.
|
|
1523
1522
|
#
|
|
1524
|
-
# The class implements FIFO type of queue. In a FIFO
|
|
1525
|
-
# added are the first retrieved.
|
|
1523
|
+
# The class implements FIFO (first in, first out) type of queue. In a FIFO
|
|
1524
|
+
# queue, the first tasks added are the first retrieved.
|
|
1526
1525
|
#
|
|
1527
1526
|
# Example:
|
|
1528
1527
|
#
|
|
@@ -1530,17 +1529,17 @@ end
|
|
|
1530
1529
|
#
|
|
1531
1530
|
# producer = Thread.new do
|
|
1532
1531
|
# 5.times do |i|
|
|
1533
|
-
#
|
|
1534
|
-
#
|
|
1535
|
-
#
|
|
1532
|
+
# sleep rand(i) # simulate expense
|
|
1533
|
+
# queue << i
|
|
1534
|
+
# puts "#{i} produced"
|
|
1536
1535
|
# end
|
|
1537
1536
|
# end
|
|
1538
1537
|
#
|
|
1539
1538
|
# consumer = Thread.new do
|
|
1540
1539
|
# 5.times do |i|
|
|
1541
|
-
#
|
|
1542
|
-
#
|
|
1543
|
-
#
|
|
1540
|
+
# value = queue.pop
|
|
1541
|
+
# sleep rand(i/2) # simulate expense
|
|
1542
|
+
# puts "consumed #{value}"
|
|
1544
1543
|
# end
|
|
1545
1544
|
# end
|
|
1546
1545
|
#
|
|
@@ -1623,6 +1622,15 @@ class Thread::Queue < Object
|
|
|
1623
1622
|
#
|
|
1624
1623
|
alias enq push
|
|
1625
1624
|
|
|
1625
|
+
# <!--
|
|
1626
|
+
# rdoc-file=thread_sync.c
|
|
1627
|
+
# - freeze
|
|
1628
|
+
# -->
|
|
1629
|
+
# Raises an exception:
|
|
1630
|
+
# Queue.new.freeze # Raises TypeError (cannot freeze #<Thread::Queue:0x...>)
|
|
1631
|
+
#
|
|
1632
|
+
def freeze: () -> bot
|
|
1633
|
+
|
|
1626
1634
|
# <!--
|
|
1627
1635
|
# rdoc-file=thread_sync.c
|
|
1628
1636
|
# - length
|
|
@@ -1699,6 +1707,15 @@ class Thread::SizedQueue < Thread::Queue
|
|
|
1699
1707
|
#
|
|
1700
1708
|
alias enq push
|
|
1701
1709
|
|
|
1710
|
+
# <!--
|
|
1711
|
+
# rdoc-file=thread_sync.c
|
|
1712
|
+
# - freeze
|
|
1713
|
+
# -->
|
|
1714
|
+
# Raises an exception:
|
|
1715
|
+
# Queue.new.freeze # Raises TypeError (cannot freeze #<Thread::Queue:0x...>)
|
|
1716
|
+
#
|
|
1717
|
+
def freeze: () -> bot
|
|
1718
|
+
|
|
1702
1719
|
# <!--
|
|
1703
1720
|
# rdoc-file=thread_sync.c
|
|
1704
1721
|
# - new(max)
|