rbs
rbs copied to clipboard
[Hash] Update Hash's signatures and tests to be correct
PHEW! This was a long one, but now Hash is finally done!
This PR updates all of the definitions within hash.rbs to be more correct, as well as modernizes the entire Hash_test.rb file, 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_Pair -
Hash.try_convertreturnsnilin theuntypedcase. -
Hash#{<,>,<=,>=}all now accepthash[untyped, untyped] -
Hash#[]now acceptsHash::_Key -
Hash#any?'s signature has been fixed: the block form actually is a tuple, and now usesEnumerable::_Pattern- It would be nice to eventually change
Enumerable::_Patternto take a generic
- It would be nice to eventually change
-
Hash#{assoc,rassoc,has_value?,key}now all takeHash::_Equals -
Hash#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 ignored -
Hash#{default,dig,delete,except,fetch,fetch_values,has_key?,slice,values_at}now all acceptHash::_Key, and any related blocks also do as well -
Hash#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 returnsvoidnotuntyped -
Hash#flattennow explicitly handles a level of0, and now acceptsints -
Hash#{merge,merge!}now both accepthash. Unfortunately, formergereturn type isHash, but really it should be "instance[A | K, B | V]" -
Hash#freezehas been added -
Hash#replacenow acceptshash - The alias pairs
size/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 added -
Hash#initialize's proc now accepts aninstance
Pushed a new version which retains %a{implicitly-returns-nil} on []. removing that should be another PR.