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.
Context
TypedHash
inherits fromHashWithIndifferentAccess
, a while ago many methods like.except()
would return a trueHashWithIndifferentAccess
, but recently they changed to return an instance of the same class than the initial hash.First
slice
in 2017 rails/rails@d6f3b91 and more recentlyexcept
in 2019: rails/rails@a805d72#diff-9f4b3d7342097a6f22290f147a09b77bThe problem with this is that
TypedHash
can contain default values for keys, so if you clear a a key with a default, it will be reset on the new instance, which makes for confusing defaults.e.g.:
{age: 42}.except(:age) => {age: 0}
while you'd likely expect{}
.Solution
We first cast to
HashWIthIndifferentAccess
before calling these methods.@rafaelfranca thoughts?