Hard-to-read yaml files

From my point of view, one of the advantages of YAML files is that
they’re easy to read and edit using normal text editors,
and don’t have all the excess cruft of XML files; yet working with
Chinese vocabulary lists has revealed some odd behavior.

Here’s my program and it’s output:

Is there some way to get the output I would like to see. The output of
yaml is not readable by humans, and I can’t verify it much
less change it.

Thanks in advance for any pointers.

Bryan

#!/usr/bin/env ruby

coding: utf-8

puts RUBY_VERSION
require ‘yaml’

vocab = {
“我” => “wǒ”,
“你” => “nǐ”
}

File.open(“VOCAB”, “w”) do |file|
YAML.dump(vocab, file)
file.puts “-------------------------”
file.puts “# This is what I would prefer to see”
file.puts “—”
vocab.each do |k,v|
file.puts “#{k}: #{v}”
end
end
puts cat VOCAB
END

What follows it the output from the above program

1.9.2

“\xE6\x88\x91”: “w\xC7\x92”
“\xE4\xBD\xA0”: “n\xC7\x90”

Am 27.05.2013 21:05, schrieb Bryan L.:

From my point of view, one of the advantages of YAML files is that they’re easy
to read and edit using normal text editors,
and don’t have all the excess cruft of XML files; yet working with Chinese
vocabulary lists has revealed some odd behavior.

Here’s my program and it’s output:

Is there some way to get the output I would like to see. The output of yaml is
not readable by humans, and I can’t verify it much
less change it.
[…]

Do you need to use 1.9.2?

Since 1.9.3 and its new default YAML engine “psych”, strings encoded
in UTF-8 should be dumped as UTF-8.

If upgrading to 1.9.3 or 2.0 is no option, set “psych” explicitly
(you probably will need to install the “psych” gem first) with

 require 'yaml'
 YAML::ENGINE.yamler='psych'
 ...

or try searching with “utf-8 yaml ruby” for workarounds.