Issue #17472 has been updated by lamont (Lamont Granquist).


+1 on adding this.

There are any number of bugs which are caused by reading mixed symbols and strings into Hashes, then round tripping them through JSON and having them change one way or the other.

I mildly disliked the use of Mash structures in Chef for about the first 5 years I used them, thinking they were too clever, until I came around to this realization that it let you export a Hash-like structure as an API which consumers could then use and not have to worry about injecting some JSON that had symbolized keys on it and getting into deep symbols-vs-strings confusion.  That whole issue goes away, which is very novice-friendly.  What is left is that mixed syntax when writing code is considered to be ugly, but that can generally be fixed by rubocop automatic linting rules and community standards.

And if you don't like that, its cool, you don't have to use it.  I would love to see it as a core language feature though.  Although I really need to be able to inherit from the class and wrap convert_key/convert_value and it would be useful to have a private regular_writer/regular_update bypass (for performance) that subclasses could use for already-converted access.

----------------------------------------
Feature #17472: HashWithIndifferentAccess like Hash extension
https://bugs.ruby-lang.org/issues/17472#change-91233

* Author: naruse (Yui NARUSE)
* Status: Open
* Priority: Normal
* Target version: 3.1
----------------------------------------
Rails has [ActiveSupport::HashWithIndifferentAccess](https://api.rubyonrails.org/classes/ActiveSupport/HashWithIndifferentAccess.html), which is widely used in Rails to handle Request, Session, ActionView's form construction, ActiveRecord's DB communication, and so on. It receives String or Symbol and normalize them to fetch the value. But it is implemented with Ruby. If we provide C implementation of that, Rails will gain the performance improvement.

summary of previous discussion: https://github.com/rails/rails/pull/40182#issuecomment-687607812



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>