GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Maintain subclasses of Hash when calling Hash#slice by jimmycuadra · Pull Request #250 · ruby-i18n/i18n

Conversation

@jimmycuadra

@jimmycuadra jimmycuadra commented Apr 12, 2014

Copy link
Copy Markdown
Contributor

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@jimmycuadra
Maintain subclasses of Hash when calling Hash#slice.
08293a4
@carlosantoniodasilva

carlosantoniodasilva commented Jan 10, 2015

Copy link
Copy Markdown
Member

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

Thanks.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jimmycuadra

jimmycuadra commented Jan 11, 2015

Copy link
Copy Markdown
Contributor Author

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

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

radar commented Nov 17, 2016

Copy link
Copy Markdown
Collaborator

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.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@radar radar closed this in 6f291c4 Nov 17, 2016
@amatsuda amatsuda mentioned this pull request Oct 27, 2017
Fix Hash#slice behavior not to return a subclass instance #390
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

0.8.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@jimmycuadra @carlosantoniodasilva @radar
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.
You are visitor 01402605 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.