简体   繁体   中英

ruby to_yaml 2.0.0 adds !ruby/object:Hash but YAML.load won't read it

Is there a way to disable ruby 2.0.0 YAML's suffixing with ruby type info?

I just upgraded to ruby 2.0.0 and I'm having YAML problems. I read-update-write a yaml file that previously looked like this

test:
  test2:
    somevar: hello

When I feed this into ruby 200, it reads OK but writes:

test: !ruby/object:Hash
  test2: !ruby/object:Hash
    somevar: hello

When I rerun the program YAML.load reads nothing.

myH = YAML.load_file( YAML_FPATH )
puts "Yaml as Hash:" + myH.inspect
>> Yaml as Hash: {}

Curiously, if I pass the "test: !ruby/object:Hash" version of the file to ruby 1.8.7, it reads the suffixed file OK and writes a non-suffixed file.

Problem found: I modified hash.to_yaml so that it sorts the keys. Since my code is based on hash.to_yaml 1.8.7 I need to revise it based on hash.to_yaml 2.0.0.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM