You seem to have found a sufficient answer, but I thought that I would send it in the usual Ruby way.
require 'base64'
h = { :first => "John", :age => 23 }
encoded = Base64.encode64(Marshal.dump(h))
h = Marshal.load(Base64.decode64(encoded))
Ruby (, JSON DB), , cookie Rails . cookie , .