1

More specifically. Is it possible to get Psych to choose the same anchor numbers each time an equivalent hash(dictionary) is serialized?

I run YAML.dump(some_hash), then later I run YAML.dump(some_other_hash). The hashes are deeply identical, but do not necessarily occupy the same memory.

some_hash's YAML has an anchor *70312330894080 while some_other_hash has *70312318281380.

I would like identical hashes to yield identical YAML. So that I can test for sameness by string-comparing the YAML.

Thanks, Matt

metaquanta
  • 11
  • 2
  • 1
    Yaml [uses the `object_id` as the anchor name](https://github.com/tenderlove/psych/blob/v2.0.4/lib/psych/visitors/yaml_tree.rb#L23), and there’s no way to alter this without patching it. [I answered a similar question about this](http://stackoverflow.com/questions/13583588/read-and-write-yaml-files-without-destroying-anchors-and-aliases/13588273#13588273), perhaps that gives you an idea? – matt Jul 23 '14 at 21:25
  • That gives me an idea: to look elsewhere. Thanks. It's still an answer if the answer is "no" – metaquanta Jul 23 '14 at 21:32
  • @matt, You wouldn't happen to know if `Marshal` has a similar problem? – metaquanta Jul 23 '14 at 21:34
  • Sorry, I don’t know about Marshal. – matt Jul 23 '14 at 21:36

0 Answers0