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

Maintain subclasses of Hash when calling Hash#slice #250

wants to merge 1 commit into from


Copy link

@jimmycuadra jimmycuadra commented Apr 12, 2014

This patch corrects i18n's implementation of Hash#slice so that it always returns an object of the same class it was originally called on.

In the current implementation, it creates a new hash, copies the selected key/value pairs into it, and returns it. This causes the returned value to be a different class, in the case where the original object was a subclass of Hash. This behavior is problematic when using something like Hashie or HashWithIndifferentAccess, because translation string interpolation only works for symbols, and keys can be copied into the new hash as strings, depending on the implementation of the subclass.

I discovered this in another library that returns Hashie::Rash objects, which work like allow symbol and string key access, but when copied by i18n's Hash#slice, lose their ability to look up values by symbol keys.

Copy link

carlosantoniodasilva commented Jan 10, 2015

@jimmycuadra is this library you comment not using Rails at all? Because if it is, it should be picking Rails' version over I18n I believe.

Anyway, people relying on I18n's core extensions make me really sad. Maybe I'll deprecate this on the future.


Copy link
Contributor Author

jimmycuadra commented Jan 11, 2015

The library I was referring to is rmoriz/digital_ocean, which does not involve Rails.

@radar radar added this to the 0.8.0 milestone Nov 17, 2016
Copy link

radar commented Nov 17, 2016

Thanks @jimmycuadra. I've manually applied this to master now (with hub am -3) and fixed the conflicts. This'll be included in the 0.8.0 release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
None yet

Successfully merging this pull request may close these issues.

None yet

3 participants