diff --git a/core/hash.rbs b/core/hash.rbs index 0a56bb66f..c0f3cb585 100644 --- a/core/hash.rbs +++ b/core/hash.rbs @@ -469,15 +469,29 @@ # * #transform_values: Returns a copy of `self` with modified values. # * #transform_values!: Modifies values in `self`. # -class Hash[unchecked out K, unchecked out V] < Object +class Hash[unchecked out K, unchecked out V] include Enumerable[[ K, V ]] + # Interface that indicates a type can be used as a key to `Hash` lookup methods. + # interface _Key def hash: () -> Integer def eql?: (untyped rhs) -> boolish end + # Interface that indicates a type convertible to `[ K, V ]` via its `#to_ary` method. + # + interface _Pair[K, V] + def to_ary: () -> [ K, V ] + end + + # Interface for comparing equality of types. + # + interface _Equals + def ==: (untyped other) -> boolish + end + # # - def deconstruct_keys: (Array[K] | nil) -> self + def deconstruct_keys: (untyped) -> self # # With a block given, calls the block with each key-value pair; returns `self`: @@ -1015,8 +1031,8 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Iterating](rdoc-ref:Hash@Methods+for+Iterating). # - def each: () { ([ K, V ] arg0) -> untyped } -> self - | () -> ::Enumerator[[ K, V ], self] + def each: () -> Enumerator[[ K, V ], self] + | () { ([ K, V ] pair) -> void } -> self # # With a block given, calls the block with each entry's key and value; returns a @@ -1200,8 +1216,8 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Deleting](rdoc-ref:Hash@Methods+for+Deleting). # - def filter: () { (K, V) -> boolish } -> ::Hash[K, V] - | () -> ::Enumerator[[ K, V ], ::Hash[K, V]] + def select: () -> Enumerator[[ K, V ], Hash[K, V]] + | () { (K key, V value) -> boolish } -> Hash[K, V] # # With a block given, calls the block with each entry's key and value; removes @@ -1217,8 +1233,8 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Deleting](rdoc-ref:Hash@Methods+for+Deleting). # - def filter!: () { (K, V) -> boolish } -> self? - | () -> ::Enumerator[[ K, V ], self?] + def select!: () -> Enumerator[[ K, V ], self?] + | () { (K key, V value) -> boolish } -> self? # # Returns whether `key` is a key in `self`: @@ -1267,7 +1283,7 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: [Methods for Querying](rdoc-ref:Hash@Methods+for+Querying). # - def has_key?: (_Key) -> bool + def has_key?: (_Key key) -> bool # + # # Returns the count of entries in `self`: # # {foo: 0, bar: 1, baz: 2}.size # => 3 # # Related: see [Methods for Querying](rdoc-ref:Hash@Methods+for+Querying). # - def length: () -> Integer + def size: () -> Integer # # Returns whether `key` is a key in `self`: @@ -1467,8 +1487,8 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Assigning](rdoc-ref:Hash@Methods+for+Assigning). # - def merge: [A, B] (*::Hash[A, B] other_hashes) -> ::Hash[A | K, B | V] - | [A, B, C] (*::Hash[A, B] other_hashes) { (K key, V oldval, B newval) -> C } -> ::Hash[A | K, B | V | C] + def merge: [A, B] (*hash[A, B] other_hashes) -> Hash[A | K, B | V] + | [A, B, C] (*hash[A, B] other_hashes) { (K key, V oldval, B newval) -> C } -> Hash[A | K, B | V | C] # # Updates values and/or adds entries to `self`; returns `self`. @@ -1511,8 +1531,8 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Assigning](rdoc-ref:Hash@Methods+for+Assigning). # - def merge!: (*::Hash[K, V] other_hashes) -> self - | (*::Hash[K, V] other_hashes) { (K key, V oldval, V newval) -> V } -> self + def merge!: (*hash[K, V] other_hashes) -> self + | (*hash[K, V] other_hashes) { (K key, V oldval, V newval) -> V } -> self # # Replaces the entire contents of `self` with the contents of `other_hash`; @@ -1602,7 +1624,7 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Assigning](rdoc-ref:Hash@Methods+for+Assigning). # - def replace: (Hash[K, V]) -> self + def replace: (hash[K, V] other) -> self # # Associates the given `object` with the given `key`; returns `object`. @@ -1723,7 +1745,7 @@ class Hash[unchecked out K, unchecked out V] < Object # # Related: see [Methods for Converting](rdoc-ref:Hash@Methods+for+Converting). # - def to_a: () -> ::Array[[ K, V ]] + def to_a: () -> Array[[ K, V ]] #