I accidentally saved a Ruby hash to string in Ruby 1.9 by calling my_hash.to_s
which is equal to my_hash.inspect
. This gave me a string like this:
'{"foo"=>{"bar"=>"baz", "qux"=>"quux"}'
I now want to revert this back into a hash. How is this done?
I'm not looking for an explanation on other serialisation techniques, I know them. I just need a way to revert this back so I can save it the right way.
The fastest answer is: eval
.
my_hash = eval(my_str_hash)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With