Feature #9980
closedCreate HashWithIndiferentAccess using new syntax {a: 1}i
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