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/hash.rbs
CHANGED
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
#
|
|
79
79
|
# You can create a Hash object explicitly with:
|
|
80
80
|
#
|
|
81
|
-
# * A [hash literal](
|
|
81
|
+
# * A [hash literal](rdoc-ref:syntax/literals.rdoc@Hash+Literals).
|
|
82
82
|
#
|
|
83
83
|
#
|
|
84
84
|
# You can convert certain objects to Hashes with:
|
|
85
85
|
#
|
|
86
|
-
# * Method
|
|
86
|
+
# * Method #Hash.
|
|
87
87
|
#
|
|
88
88
|
#
|
|
89
89
|
# You can create a Hash by calling method Hash.new.
|
|
@@ -349,211 +349,152 @@
|
|
|
349
349
|
#
|
|
350
350
|
# First, what's elsewhere. Class Hash:
|
|
351
351
|
#
|
|
352
|
-
# * Inherits from [class
|
|
353
|
-
#
|
|
354
|
-
# * Includes [module
|
|
355
|
-
# Enumerable](Enumerable.html#module-Enumerable-label-What-27s+Here), which
|
|
352
|
+
# * Inherits from [class Object](rdoc-ref:Object@What-27s+Here).
|
|
353
|
+
# * Includes [module Enumerable](rdoc-ref:Enumerable@What-27s+Here), which
|
|
356
354
|
# provides dozens of additional methods.
|
|
357
355
|
#
|
|
358
356
|
#
|
|
359
357
|
# Here, class Hash provides methods that are useful for:
|
|
360
358
|
#
|
|
361
|
-
# * [Creating a Hash](
|
|
362
|
-
# * [Setting Hash State](
|
|
363
|
-
# * [Querying](
|
|
364
|
-
# * [Comparing](
|
|
365
|
-
# * [Fetching](
|
|
366
|
-
# * [Assigning](
|
|
367
|
-
# * [Deleting](
|
|
368
|
-
# * [Iterating](
|
|
369
|
-
# * [Converting](
|
|
359
|
+
# * [Creating a Hash](rdoc-ref:Hash@Methods+for+Creating+a+Hash)
|
|
360
|
+
# * [Setting Hash State](rdoc-ref:Hash@Methods+for+Setting+Hash+State)
|
|
361
|
+
# * [Querying](rdoc-ref:Hash@Methods+for+Querying)
|
|
362
|
+
# * [Comparing](rdoc-ref:Hash@Methods+for+Comparing)
|
|
363
|
+
# * [Fetching](rdoc-ref:Hash@Methods+for+Fetching)
|
|
364
|
+
# * [Assigning](rdoc-ref:Hash@Methods+for+Assigning)
|
|
365
|
+
# * [Deleting](rdoc-ref:Hash@Methods+for+Deleting)
|
|
366
|
+
# * [Iterating](rdoc-ref:Hash@Methods+for+Iterating)
|
|
367
|
+
# * [Converting](rdoc-ref:Hash@Methods+for+Converting)
|
|
370
368
|
# * [Transforming Keys and
|
|
371
|
-
# Values](
|
|
372
|
-
# * [And more....](
|
|
369
|
+
# Values](rdoc-ref:Hash@Methods+for+Transforming+Keys+and+Values)
|
|
370
|
+
# * [And more....](rdoc-ref:Hash@Other+Methods)
|
|
373
371
|
#
|
|
374
372
|
#
|
|
375
373
|
# Class Hash also includes methods from module Enumerable.
|
|
376
374
|
#
|
|
377
375
|
# #### Methods for Creating a Hash
|
|
378
376
|
#
|
|
379
|
-
# ::[]
|
|
380
|
-
# :
|
|
381
|
-
# ::new
|
|
382
|
-
# : Returns a new empty hash.
|
|
383
|
-
# ::try_convert
|
|
384
|
-
# : Returns a new hash created from a given object.
|
|
377
|
+
# * ::[]: Returns a new hash populated with given objects.
|
|
378
|
+
# * ::new: Returns a new empty hash.
|
|
379
|
+
# * ::try_convert: Returns a new hash created from a given object.
|
|
385
380
|
#
|
|
386
381
|
#
|
|
387
382
|
# #### Methods for Setting Hash State
|
|
388
383
|
#
|
|
389
|
-
# #compare_by_identity
|
|
390
|
-
#
|
|
391
|
-
# #default
|
|
392
|
-
#
|
|
393
|
-
# #
|
|
394
|
-
#
|
|
395
|
-
# #rehash
|
|
396
|
-
# : Rebuilds the hash table by recomputing the hash index for each key.
|
|
384
|
+
# * #compare_by_identity: Sets `self` to consider only identity in comparing
|
|
385
|
+
# keys.
|
|
386
|
+
# * #default=: Sets the default to a given value.
|
|
387
|
+
# * #default_proc=: Sets the default proc to a given proc.
|
|
388
|
+
# * #rehash: Rebuilds the hash table by recomputing the hash index for each
|
|
389
|
+
# key.
|
|
397
390
|
#
|
|
398
391
|
#
|
|
399
392
|
# #### Methods for Querying
|
|
400
393
|
#
|
|
401
|
-
# #any
|
|
402
|
-
#
|
|
403
|
-
#
|
|
404
|
-
# :
|
|
405
|
-
# #default
|
|
406
|
-
#
|
|
407
|
-
# #
|
|
408
|
-
# :
|
|
409
|
-
# #
|
|
410
|
-
#
|
|
411
|
-
#
|
|
412
|
-
#
|
|
413
|
-
# #
|
|
414
|
-
# : Returns the integer hash code.
|
|
415
|
-
# #has_value?
|
|
416
|
-
# : Returns whether a given object is a value in `self`.
|
|
417
|
-
# #include?, #has_key?, #member?, #key?
|
|
418
|
-
# : Returns whether a given object is a key in `self`.
|
|
419
|
-
# #length, #size
|
|
420
|
-
# : Returns the count of entries.
|
|
421
|
-
# #value?
|
|
422
|
-
# : Returns whether a given object is a value in `self`.
|
|
394
|
+
# * #any?: Returns whether any element satisfies a given criterion.
|
|
395
|
+
# * #compare_by_identity?: Returns whether the hash considers only identity
|
|
396
|
+
# when comparing keys.
|
|
397
|
+
# * #default: Returns the default value, or the default value for a given key.
|
|
398
|
+
# * #default_proc: Returns the default proc.
|
|
399
|
+
# * #empty?: Returns whether there are no entries.
|
|
400
|
+
# * #eql?: Returns whether a given object is equal to `self`.
|
|
401
|
+
# * #hash: Returns the integer hash code.
|
|
402
|
+
# * #has_value?: Returns whether a given object is a value in `self`.
|
|
403
|
+
# * #include?, #has_key?, #member?, #key?: Returns whether a given object is a
|
|
404
|
+
# key in `self`.
|
|
405
|
+
# * #length, #size: Returns the count of entries.
|
|
406
|
+
# * #value?: Returns whether a given object is a value in `self`.
|
|
423
407
|
#
|
|
424
408
|
#
|
|
425
409
|
# #### Methods for Comparing
|
|
426
410
|
#
|
|
427
|
-
#
|
|
428
|
-
#
|
|
429
|
-
#
|
|
430
|
-
#
|
|
431
|
-
#
|
|
432
|
-
# : Returns whether a given object is equal to `self`.
|
|
433
|
-
# [#>](#method-i-3E)
|
|
434
|
-
# : Returns whether `self` is a proper superset of a given object
|
|
435
|
-
# [#>=](#method-i-3E-3D)
|
|
436
|
-
# : Returns whether `self` is a proper superset of a given object.
|
|
411
|
+
# * #<: Returns whether `self` is a proper subset of a given object.
|
|
412
|
+
# * #<=: Returns whether `self` is a subset of a given object.
|
|
413
|
+
# * #==: Returns whether a given object is equal to `self`.
|
|
414
|
+
# * #>: Returns whether `self` is a proper superset of a given object
|
|
415
|
+
# * #>=: Returns whether `self` is a proper superset of a given object.
|
|
437
416
|
#
|
|
438
417
|
#
|
|
439
418
|
# #### Methods for Fetching
|
|
440
419
|
#
|
|
441
|
-
# #[]
|
|
442
|
-
# :
|
|
443
|
-
# #
|
|
444
|
-
#
|
|
445
|
-
# #
|
|
446
|
-
# :
|
|
447
|
-
#
|
|
448
|
-
# #
|
|
449
|
-
# :
|
|
450
|
-
# #
|
|
451
|
-
# : Returns array containing the values associated with given keys.
|
|
452
|
-
# #key
|
|
453
|
-
# : Returns the key for the first-found entry with a given value.
|
|
454
|
-
# #keys
|
|
455
|
-
# : Returns an array containing all keys in `self`.
|
|
456
|
-
# #rassoc
|
|
457
|
-
# : Returns a 2-element array consisting of the key and value of the
|
|
420
|
+
# * #[]: Returns the value associated with a given key.
|
|
421
|
+
# * #assoc: Returns a 2-element array containing a given key and its value.
|
|
422
|
+
# * #dig: Returns the object in nested objects that is specified by a given
|
|
423
|
+
# key and additional arguments.
|
|
424
|
+
# * #fetch: Returns the value for a given key.
|
|
425
|
+
# * #fetch_values: Returns array containing the values associated with given
|
|
426
|
+
# keys.
|
|
427
|
+
# * #key: Returns the key for the first-found entry with a given value.
|
|
428
|
+
# * #keys: Returns an array containing all keys in `self`.
|
|
429
|
+
# * #rassoc: Returns a 2-element array consisting of the key and value of the
|
|
458
430
|
# first-found entry having a given value.
|
|
459
|
-
# #values
|
|
460
|
-
# :
|
|
461
|
-
# #values_at
|
|
462
|
-
# : Returns an array containing values for given keys.
|
|
431
|
+
# * #values: Returns an array containing all values in `self`/
|
|
432
|
+
# * #values_at: Returns an array containing values for given keys.
|
|
463
433
|
#
|
|
464
434
|
#
|
|
465
435
|
# #### Methods for Assigning
|
|
466
436
|
#
|
|
467
|
-
# #[]=, #store
|
|
468
|
-
# :
|
|
469
|
-
#
|
|
470
|
-
#
|
|
471
|
-
# #
|
|
472
|
-
#
|
|
473
|
-
# #replace
|
|
474
|
-
# : Replaces the entire contents of `self` with the contents of a givan hash.
|
|
437
|
+
# * #[]=, #store: Associates a given key with a given value.
|
|
438
|
+
# * #merge: Returns the hash formed by merging each given hash into a copy of
|
|
439
|
+
# `self`.
|
|
440
|
+
# * #merge!, #update: Merges each given hash into `self`.
|
|
441
|
+
# * #replace: Replaces the entire contents of `self` with the contents of a
|
|
442
|
+
# given hash.
|
|
475
443
|
#
|
|
476
444
|
#
|
|
477
445
|
# #### Methods for Deleting
|
|
478
446
|
#
|
|
479
447
|
# These methods remove entries from `self`:
|
|
480
448
|
#
|
|
481
|
-
# #clear
|
|
482
|
-
#
|
|
483
|
-
# #
|
|
484
|
-
# :
|
|
485
|
-
# #
|
|
486
|
-
# :
|
|
487
|
-
# #
|
|
488
|
-
# :
|
|
489
|
-
# #filter!, #select!
|
|
490
|
-
# : Keep only those entries selected by a given block.
|
|
491
|
-
# #keep_if
|
|
492
|
-
# : Keep only those entries selected by a given block.
|
|
493
|
-
# #reject!
|
|
494
|
-
# : Removes entries selected by a given block.
|
|
495
|
-
# #shift
|
|
496
|
-
# : Removes and returns the first entry.
|
|
449
|
+
# * #clear: Removes all entries from `self`.
|
|
450
|
+
# * #compact!: Removes all `nil`-valued entries from `self`.
|
|
451
|
+
# * #delete: Removes the entry for a given key.
|
|
452
|
+
# * #delete_if: Removes entries selected by a given block.
|
|
453
|
+
# * #filter!, #select!: Keep only those entries selected by a given block.
|
|
454
|
+
# * #keep_if: Keep only those entries selected by a given block.
|
|
455
|
+
# * #reject!: Removes entries selected by a given block.
|
|
456
|
+
# * #shift: Removes and returns the first entry.
|
|
497
457
|
#
|
|
498
458
|
#
|
|
499
459
|
# These methods return a copy of `self` with some entries removed:
|
|
500
460
|
#
|
|
501
|
-
# #compact
|
|
502
|
-
# :
|
|
503
|
-
# #
|
|
504
|
-
#
|
|
505
|
-
# #
|
|
506
|
-
#
|
|
507
|
-
#
|
|
508
|
-
# #reject
|
|
509
|
-
# : Returns a copy of `self` with entries removed as specified by a given
|
|
510
|
-
# block.
|
|
511
|
-
# #slice
|
|
512
|
-
# : Returns a hash containing the entries for given keys.
|
|
461
|
+
# * #compact: Returns a copy of `self` with all `nil`-valued entries removed.
|
|
462
|
+
# * #except: Returns a copy of `self` with entries removed for specified keys.
|
|
463
|
+
# * #filter, #select: Returns a copy of `self` with only those entries
|
|
464
|
+
# selected by a given block.
|
|
465
|
+
# * #reject: Returns a copy of `self` with entries removed as specified by a
|
|
466
|
+
# given block.
|
|
467
|
+
# * #slice: Returns a hash containing the entries for given keys.
|
|
513
468
|
#
|
|
514
469
|
#
|
|
515
470
|
# #### Methods for Iterating
|
|
516
|
-
# #each, #each_pair
|
|
517
|
-
# :
|
|
518
|
-
# #
|
|
519
|
-
# : Calls a given block with each key.
|
|
520
|
-
# #each_value
|
|
521
|
-
# : Calls a given block with each value.
|
|
471
|
+
# * #each, #each_pair: Calls a given block with each key-value pair.
|
|
472
|
+
# * #each_key: Calls a given block with each key.
|
|
473
|
+
# * #each_value: Calls a given block with each value.
|
|
522
474
|
#
|
|
523
475
|
#
|
|
524
476
|
# #### Methods for Converting
|
|
525
477
|
#
|
|
526
|
-
# #inspect, #to_s
|
|
527
|
-
# :
|
|
528
|
-
#
|
|
529
|
-
# :
|
|
530
|
-
#
|
|
531
|
-
# #
|
|
532
|
-
# :
|
|
533
|
-
# the entries from `self`.
|
|
534
|
-
# #to_hash
|
|
535
|
-
# : Returns `self`.
|
|
536
|
-
# #to_proc
|
|
537
|
-
# : Returns a proc that maps a given key to its value.
|
|
478
|
+
# * #inspect, #to_s: Returns a new String containing the hash entries.
|
|
479
|
+
# * #to_a: Returns a new array of 2-element arrays; each nested array contains
|
|
480
|
+
# a key-value pair from `self`.
|
|
481
|
+
# * #to_h: Returns `self` if a Hash; if a subclass of Hash, returns a Hash
|
|
482
|
+
# containing the entries from `self`.
|
|
483
|
+
# * #to_hash: Returns `self`.
|
|
484
|
+
# * #to_proc: Returns a proc that maps a given key to its value.
|
|
538
485
|
#
|
|
539
486
|
#
|
|
540
487
|
# #### Methods for Transforming Keys and Values
|
|
541
488
|
#
|
|
542
|
-
# #transform_keys
|
|
543
|
-
#
|
|
544
|
-
# #
|
|
545
|
-
#
|
|
546
|
-
# #transform_values
|
|
547
|
-
# : Returns a copy of `self` with modified values.
|
|
548
|
-
# #transform_values!
|
|
549
|
-
# : Modifies values in `self`.
|
|
489
|
+
# * #transform_keys: Returns a copy of `self` with modified keys.
|
|
490
|
+
# * #transform_keys!: Modifies keys in `self`
|
|
491
|
+
# * #transform_values: Returns a copy of `self` with modified values.
|
|
492
|
+
# * #transform_values!: Modifies values in `self`.
|
|
550
493
|
#
|
|
551
494
|
#
|
|
552
495
|
# #### Other Methods
|
|
553
|
-
# #flatten
|
|
554
|
-
# :
|
|
555
|
-
# #invert
|
|
556
|
-
# : Returns a hash with the each key-value pair inverted.
|
|
496
|
+
# * #flatten: Returns an array that is a 1-dimensional flattening of `self`.
|
|
497
|
+
# * #invert: Returns a hash with the each key-value pair inverted.
|
|
557
498
|
#
|
|
558
499
|
class Hash[unchecked out K, unchecked out V] < Object
|
|
559
500
|
include Enumerable[[ K, V ]]
|
|
@@ -694,7 +635,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
694
635
|
# h[:foo] # => 0
|
|
695
636
|
#
|
|
696
637
|
# If `key` is not found, returns a default value (see [Default
|
|
697
|
-
# Values](
|
|
638
|
+
# Values](rdoc-ref:Hash@Default+Values)):
|
|
698
639
|
# h = {foo: 0, bar: 1, baz: 2}
|
|
699
640
|
# h[:nosuch] # => nil
|
|
700
641
|
#
|
|
@@ -710,14 +651,14 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
710
651
|
# Associates the given `value` with the given `key`; returns `value`.
|
|
711
652
|
#
|
|
712
653
|
# If the given `key` exists, replaces its value with the given `value`; the
|
|
713
|
-
# ordering is not affected (see [Entry Order](
|
|
654
|
+
# ordering is not affected (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
|
714
655
|
# h = {foo: 0, bar: 1}
|
|
715
656
|
# h[:foo] = 2 # => 2
|
|
716
657
|
# h.store(:bar, 3) # => 3
|
|
717
658
|
# h # => {:foo=>2, :bar=>3}
|
|
718
659
|
#
|
|
719
660
|
# If `key` does not exist, adds the `key` and `value`; the new entry is last in
|
|
720
|
-
# the order (see [Entry Order](
|
|
661
|
+
# the order (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
|
721
662
|
# h = {foo: 0, bar: 1}
|
|
722
663
|
# h[:baz] = 2 # => 2
|
|
723
664
|
# h.store(:bat, 3) # => 3
|
|
@@ -847,7 +788,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
847
788
|
# -->
|
|
848
789
|
# Returns the default value for the given `key`. The returned value will be
|
|
849
790
|
# determined either by the default proc or by the default value. See [Default
|
|
850
|
-
# Values](
|
|
791
|
+
# Values](rdoc-ref:Hash@Default+Values).
|
|
851
792
|
#
|
|
852
793
|
# With no argument, returns the current default value:
|
|
853
794
|
# h = {}
|
|
@@ -871,7 +812,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
871
812
|
# h.default = false # => false
|
|
872
813
|
# h.default # => false
|
|
873
814
|
#
|
|
874
|
-
# See [Default Values](
|
|
815
|
+
# See [Default Values](rdoc-ref:Hash@Default+Values).
|
|
875
816
|
#
|
|
876
817
|
def default=: (V arg0) -> V
|
|
877
818
|
|
|
@@ -880,7 +821,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
880
821
|
# - hash.default_proc -> proc or nil
|
|
881
822
|
# -->
|
|
882
823
|
# Returns the default proc for `self` (see [Default
|
|
883
|
-
# Values](
|
|
824
|
+
# Values](rdoc-ref:Hash@Default+Values)):
|
|
884
825
|
# h = {}
|
|
885
826
|
# h.default_proc # => nil
|
|
886
827
|
# h.default_proc = proc {|hash, key| "Default value for #{key}" }
|
|
@@ -893,7 +834,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
893
834
|
# - hash.default_proc = proc -> proc
|
|
894
835
|
# -->
|
|
895
836
|
# Sets the default proc for `self` to `proc`: (see [Default
|
|
896
|
-
# Values](
|
|
837
|
+
# Values](rdoc-ref:Hash@Default+Values)):
|
|
897
838
|
# h = {}
|
|
898
839
|
# h.default_proc # => nil
|
|
899
840
|
# h.default_proc = proc { |hash, key| "Default value for #{key}" }
|
|
@@ -970,8 +911,8 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
970
911
|
# h = {foo: {bar: [:a, :b, :c]}}
|
|
971
912
|
# h.dig(:foo, :bar, 2) # => :c
|
|
972
913
|
#
|
|
973
|
-
# This method will use the [default values](
|
|
974
|
-
#
|
|
914
|
+
# This method will use the [default values](rdoc-ref:Hash@Default+Values) for
|
|
915
|
+
# keys that are not present:
|
|
975
916
|
# h = {foo: {bar: [:a, :b, :c]}}
|
|
976
917
|
# h.dig(:hello) # => nil
|
|
977
918
|
# h.default_proc = -> (hash, _key) { hash }
|
|
@@ -1321,7 +1262,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1321
1262
|
# h1 # => {0=>:foo, 1=>:bar, 2=>:baz}
|
|
1322
1263
|
#
|
|
1323
1264
|
# Overwrites any repeated new keys: (see [Entry
|
|
1324
|
-
# Order](
|
|
1265
|
+
# Order](rdoc-ref:Hash@Entry+Order)):
|
|
1325
1266
|
# h = {foo: 0, bar: 0, baz: 0}
|
|
1326
1267
|
# h.invert # => {0=>:baz}
|
|
1327
1268
|
#
|
|
@@ -1350,7 +1291,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1350
1291
|
# - hash.key(value) -> key or nil
|
|
1351
1292
|
# -->
|
|
1352
1293
|
# Returns the key for the first-found entry with the given `value` (see [Entry
|
|
1353
|
-
# Order](
|
|
1294
|
+
# Order](rdoc-ref:Hash@Entry+Order)):
|
|
1354
1295
|
# h = {foo: 0, bar: 2, baz: 2}
|
|
1355
1296
|
# h.key(0) # => :foo
|
|
1356
1297
|
# h.key(2) # => :bar
|
|
@@ -1505,7 +1446,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1505
1446
|
# -->
|
|
1506
1447
|
# Returns a new 2-element Array consisting of the key and value of the
|
|
1507
1448
|
# first-found entry whose value is `==` to value (see [Entry
|
|
1508
|
-
# Order](
|
|
1449
|
+
# Order](rdoc-ref:Hash@Entry+Order)):
|
|
1509
1450
|
# h = {foo: 0, bar: 1, baz: 1}
|
|
1510
1451
|
# h.rassoc(1) # => [:bar, 1]
|
|
1511
1452
|
#
|
|
@@ -1522,7 +1463,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1522
1463
|
#
|
|
1523
1464
|
# The hash table becomes invalid if the hash value of a key has changed after
|
|
1524
1465
|
# the entry was created. See [Modifying an Active Hash
|
|
1525
|
-
# Key](
|
|
1466
|
+
# Key](rdoc-ref:Hash@Modifying+an+Active+Hash+Key).
|
|
1526
1467
|
#
|
|
1527
1468
|
def rehash: () -> self
|
|
1528
1469
|
|
|
@@ -1616,17 +1557,15 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1616
1557
|
|
|
1617
1558
|
# <!--
|
|
1618
1559
|
# rdoc-file=hash.c
|
|
1619
|
-
# - hash.shift -> [key, value] or
|
|
1560
|
+
# - hash.shift -> [key, value] or nil
|
|
1620
1561
|
# -->
|
|
1621
|
-
# Removes the first hash entry (see [Entry
|
|
1622
|
-
#
|
|
1623
|
-
# the removed key and value:
|
|
1562
|
+
# Removes the first hash entry (see [Entry Order](rdoc-ref:Hash@Entry+Order));
|
|
1563
|
+
# returns a 2-element Array containing the removed key and value:
|
|
1624
1564
|
# h = {foo: 0, bar: 1, baz: 2}
|
|
1625
1565
|
# h.shift # => [:foo, 0]
|
|
1626
1566
|
# h # => {:bar=>1, :baz=>2}
|
|
1627
1567
|
#
|
|
1628
|
-
# Returns
|
|
1629
|
-
# Values](#class-Hash-label-Default+Values)).
|
|
1568
|
+
# Returns nil if the hash is empty.
|
|
1630
1569
|
#
|
|
1631
1570
|
def shift: () -> [ K, V ]?
|
|
1632
1571
|
|
|
@@ -1660,14 +1599,14 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1660
1599
|
# Associates the given `value` with the given `key`; returns `value`.
|
|
1661
1600
|
#
|
|
1662
1601
|
# If the given `key` exists, replaces its value with the given `value`; the
|
|
1663
|
-
# ordering is not affected (see [Entry Order](
|
|
1602
|
+
# ordering is not affected (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
|
1664
1603
|
# h = {foo: 0, bar: 1}
|
|
1665
1604
|
# h[:foo] = 2 # => 2
|
|
1666
1605
|
# h.store(:bar, 3) # => 3
|
|
1667
1606
|
# h # => {:foo=>2, :bar=>3}
|
|
1668
1607
|
#
|
|
1669
1608
|
# If `key` does not exist, adds the `key` and `value`; the new entry is last in
|
|
1670
|
-
# the order (see [Entry Order](
|
|
1609
|
+
# the order (see [Entry Order](rdoc-ref:Hash@Entry+Order)):
|
|
1671
1610
|
# h = {foo: 0, bar: 1}
|
|
1672
1611
|
# h[:baz] = 2 # => 2
|
|
1673
1612
|
# h.store(:bat, 3) # => 3
|
|
@@ -1913,8 +1852,8 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1913
1852
|
# h = {foo: 0, bar: 1, baz: 2}
|
|
1914
1853
|
# h.values_at(:baz, :foo) # => [2, 0]
|
|
1915
1854
|
#
|
|
1916
|
-
# The [default values](
|
|
1917
|
-
#
|
|
1855
|
+
# The [default values](rdoc-ref:Hash@Default+Values) are returned for any keys
|
|
1856
|
+
# that are not found:
|
|
1918
1857
|
# h.values_at(:hello, :foo) # => [nil, 0]
|
|
1919
1858
|
#
|
|
1920
1859
|
def values_at: (*K arg0) -> ::Array[V?]
|
|
@@ -1929,8 +1868,7 @@ class Hash[unchecked out K, unchecked out V] < Object
|
|
|
1929
1868
|
# Returns a new empty Hash object.
|
|
1930
1869
|
#
|
|
1931
1870
|
# The initial default value and initial default proc for the new hash depend on
|
|
1932
|
-
# which form above was used. See [Default
|
|
1933
|
-
# Values](#class-Hash-label-Default+Values).
|
|
1871
|
+
# which form above was used. See [Default Values](rdoc-ref:Hash@Default+Values).
|
|
1934
1872
|
#
|
|
1935
1873
|
# If neither an argument nor a block given, initializes both the default value
|
|
1936
1874
|
# and the default proc to `nil`:
|