[Hash] Update Hash's signatures and tests to be correct #2694
+693
−388
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
PHEW! This was a long one, but now
Hashis finally done!This PR updates all of the definitions within
hash.rbsto be more correct, as well as modernizes the entireHash_test.rbfile, which was still using the old format.A complete list of functional changes is below. Bolded ones are important.
Hash::_Pair[K, V]is added;Hash.[]andHash#to_huse it.Hash::_Equalsis added. Used byHash#{assoc,has_value?,rassoc}.Hash.[]has been changed to returninstances in theHash[a: 1]andHash[[:a, 1]]cases, and now uses_PairHash.try_convertreturnsnilin theuntypedcase.Hash#{<,>,<=,>=}all now accepthash[untyped, untyped]Hash#[]now acceptsHash::_KeyHash#any?'s signature has been fixed: the block form actually is a tuple, and now usesEnumerable::_PatternEnumerable::_Patternto take a genericHash#{assoc,rassoc,has_value?,key}now all takeHash::_EqualsHash#compactreturns aninstance. There's no real good way to represent the return value for the function, butinstanceis more accurate thanHash[K, V]Hash#deconstruct_keysnow has anuntypedargument, as it's ignoredHash#{default,dig,delete,except,fetch,fetch_values,has_key?,slice,values_at}now all acceptHash::_Key, and any related blocks also do as wellHash#default_procnow returns a(^(self, _Key) -> V)?. I'm not sure if thisselfis legal, or needs to be aninstance(or evenHash[K, V], though I don't like that because it doesnt account forHashsubclasses)Hash#default_proc=is similarly plagued withHash#default_proc's concern. Also, the three branches were split up.Hash#each{,_key,_value}'s blocks now returnsvoidnotuntypedHash#flattennow explicitly handles a level of0, and now acceptsintsHash#{merge,merge!}now both accepthash. Unfortunately, formergereturn type isHash, but really it should be "instance[A | K, B | V]"Hash#freezehas been addedHash#replacenow acceptshashsize/length,filter/select, andfilter!/select!have been swapped, to more closely match documentation. (Other aliases which matched the documentation haven't been touched)Hash#to_h's block form can now return_Pair[A, B]Hash#{transform_keys{,!}}variants with hash arguments ({a: 1}.transform_keys(a: :b) #=> {b: 1}) have been addedHash#initialize's proc now accepts aninstance