Project

General

Profile

Actions

Feature #9980

closed

Create HashWithIndiferentAccess using new syntax {a: 1}i

Added by rosenfeld (Rodrigo Rosenfeld Rosas) over 10 years ago. Updated over 10 years ago.

Status:
Rejected
Target version:
[ruby-core:63338]

Description

This is related to feature #7797. For that feature I requested a regular hash ({}) to be treated as HWIA and the current hash implementation would be available as StrictHash.new since it's not as much needed as the common case of expecting a[:a] to be the same as a['a'].

Although I still prefer the proposal in #7797, I'd like to propose an alternative syntax for a new implementation of Hash that converts symbols to strings in keys (or keys to strings, it doesn't matter). This:

{my_key: 'my_value'}i

Should be equivalent to:

HashWithIndifferentAccess.new(my_key: 'my_value') # from ActiveSupport

It doesn't have to behave exactly like the implementation from ActiveSupport. I only really care about symbols and strings being treated the same way.

This is not as great as #7797 because it will only affect user's own code rather than hashes created by other libraries (unless they decide to adopt the new syntax, which could take quite a while to keep backward compatibility with old Ruby versions). But it would already make it way more pleasant to define new hashes with indifferent access.

Maybe it could act recursively during the hash creation, but I'm fine if you think it would be more confusing than helpful. To illustrate:

{a: {b: 1}}i

could mean the same as:

{a: {b: 1}i}i

Files

feature-9980.pdf (24.8 KB) feature-9980.pdf Slide for proposal (newest from Firefox) rosenfeld (Rodrigo Rosenfeld Rosas), 06/30/2014 05:18 PM
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0