Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Hash#slice behavior not to return a subclass instance #390

Merged
merged 1 commit into from Nov 1, 2017
Merged

Fix Hash#slice behavior not to return a subclass instance #390

merged 1 commit into from Nov 1, 2017

Conversation

amatsuda
Copy link
Contributor

Hash#slice has been introduced to Ruby core Hash class in 2.5. ruby/ruby@6c50bdda

The 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.

Class.new(Hash)[:a, 1, :b, 2].select { true }.class
#=> Hash

Class.new(Hash)[:a, 1, :b, 2].reject { false }.class
#=> Hash

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.

This reverts commit 6f291c4.

This I18n original Hash#slice implementation behaves differently from that of Ruby 2.5+
@radar
Copy link
Collaborator

radar commented Nov 1, 2017

Thank you @amatsuda! I prefer your suggestion for an alternative fix to #250. Thank you for including that.

@radar radar merged commit 329ba05 into ruby-i18n:master Nov 1, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants