psych
psych copied to clipboard
Change `symbolize_names` to `symbolize_keys`
This occured to me while testing this option without the docs in front of me; it didn't work because I thought the option was named symbolize_keys (and only one day before I wrote the docs for it...). Why symbolize_names? symbolize_keys describes exactly what it does, symbolizing Hash keys, not names. Also, symbolize_keys already has some spread as a method name.
I will provide a PR if there is agreement on this.
cc @k0kubun
That's because JSON has such interface.
JSON.parse(json, symbolize_names: true)
I see. But I don’t think that consistency with JSON is a good enough justification for a poorly named option (and the only option they have in common). symbolize_keys is more to the point and used in other places (e.g. Rails provides a Hash#symbolize_keys method).
BTW, the docs for JSON need to explain(!) what „names“ means: “returns symbols for the names (keys) in a JSON object“; and: hashes have keys, not names.
I've opened this as an issue on the Ruby bug-tracker, as I agree that the current name is not clear:
https://bugs.ruby-lang.org/issues/15541
Rather than changing the name (breaking change) just create an alias.
Also agree, add an alias symbolize_keys is an alias for symbolize_names and deprecate symbolize_names.
Yea, symbolize_names is way unintuitive
Can we also update JSON gem to support symbolize_keys?
Easy fix to add an alias, have to look this up each time...