Repository navigation
Add :stringify_names option to convert symbol keys to string for dumping - #621
Conversation
|
Did a small benchmark, comparing While overall performance gains seem to be within margin of error, memory usage is consistently down. |
tenderlove
left a comment
There was a problem hiding this comment.
This seems like a fine feature, but is the option name the right thing? It's stringify_names, but that seems pretty ambiguous from the reader's perspective. Maybe stringify_symbol_keys or something?
|
I'm absolutely not married to the name. But just for the sake of the argument, Psych.safe_load("---\n!ruby/object:DateTime 2024-01-17 11:19:12.359689000 +01:00: value\nkey: value\n", symbolize_names: true, permitted_classes: [Time, DateTime])
# => {#<DateTime: 2024-01-17T11:19:12+01:00 ((2460327j,37152s,359689000n),+3600s,2299161j)>=>"value", :key=>"value"} |
Ya, you're right. Looking through commit history, it seems like that came from |
When dumping larger and/or nested Hashes, it would be useful to let Psych treat symbol keys as string keys to avoid building a new hash with string keys, just for the sake of dumping.
:stringify_namesfor dumping is conceptually the reverse of:symbolize_namesfor loading: