Fix Hash#slice behavior not to return a subclass instance #390
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.
Hash#slice
has been introduced to Ruby core Hash class in 2.5. ruby/ruby@6c50bddaThe Ruby core version of
Class(Hash)#slice
returns a new instance of Hash, not an instance of the subclass, respecting consistency with other existing Hash methods, e. g.This PR fixes the I18n original
Hash#slice
implementation to behave in the same way with that of Ruby 2.5+ simply by reverting 6f291c4.I do understand @jimmycuadra's use case described in #250, but in such case, please consider overriding
slice
inside that particular Hash subclass, just as we're doing in Active Support's hash_with_indifferent_access.rb.