psych icon indicating copy to clipboard operation
psych copied to clipboard

Change `symbolize_names` to `symbolize_keys`

Open stomar opened this issue 7 years ago • 9 comments

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.

stomar avatar Dec 01 '17 23:12 stomar

cc @k0kubun

stomar avatar Dec 03 '17 10:12 stomar

That's because JSON has such interface.

JSON.parse(json, symbolize_names: true)

k0kubun avatar Dec 03 '17 12:12 k0kubun

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.

stomar avatar Dec 03 '17 14:12 stomar

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

baweaver avatar Jan 16 '19 01:01 baweaver

Rather than changing the name (breaking change) just create an alias.

noraj avatar Oct 14 '19 13:10 noraj

Also agree, add an alias symbolize_keys is an alias for symbolize_names and deprecate symbolize_names.

ioquatix avatar Jan 28 '20 04:01 ioquatix

Yea, symbolize_names is way unintuitive

webzorg avatar Sep 04 '20 10:09 webzorg

Can we also update JSON gem to support symbolize_keys?

ioquatix avatar Sep 07 '20 06:09 ioquatix

Easy fix to add an alias, have to look this up each time...

eflukx avatar Oct 25 '20 18:10 eflukx