You can calculate your own hash based on a marshal or JSON dump object.
This computes the marshal dump MD5 hash:
require 'digest/md5' hash = { foo: "Test string", bar: [475934759, 5619827847] } Marshal::dump(hash)
Update
You can implement your own strategy, although I would not recommend changing the main functions:
class Hash def _dump(depth) # this doesn't cause a recursion because sort returns an array Marshal::dump(self.sort, depth) end def self._load(marshaled_hash) Hash[Marshal::load(marshaled_hash)] end end Marshal::dump({foo:1, bar:2})
source share