If you deal with a lot of YAML in your Ruby code, especially migrating from Ruby 1.8.x to 1.9.2 and 1.9.3, then you may have run into some of the numerous issues with YAML incompatibility. I won’t bore you with a lot of specifics, because most of these bugs are transient, but here are the basic facts:
Syck is the antiquated builtin legacy YAML driver for Ruby.
Psych is the new-fangled modern YAML driver for Ruby.
Ruby 1.9.3 always defaults to Psych.
Ruby 1.9.2 may default to Psych depending on the system state Ruby is compiled.
You can check which engine is active in Ruby 1.9.x like so:
Hopefully you are using Psych for everything, but if you have legacy Syck YAML files lying around you could be in for some pain because they are not necessarily compatible. In my case, I had a bunch of i18n translation files emitted with Syck which uses an incompatible escape code structure instead of plain utf-8, thereby rendering the files unreadable by both Psych and humans alike. My solution was a little script utilizing the fact that the engine can be swapped dynamically:
require'yaml'require'fileutils'ifARGV.empty?
$stderr.puts "! Must pass one or more filenames to convert from Syck output to Psych output."
exit 1end
bad_files =ARGV.select{ |f| ! File.exists?(f) }
if bad_files.any?
$stderr.puts "! Aborting because the following files do not exist:"$stderr.puts bad_files
exit 1enddef use_syck
YAML::ENGINE.yamler ='syck'raise"Oops! Something went horribly wrong."unlessYAML==Syckenddef use_psych
YAML::ENGINE.yamler ='psych'raise"Oops! Something went horribly wrong."unlessYAML==PsychendARGV.each do |filename|
$stdout.print "Converting #{filename} from Syck to Psych..."
use_syck
hash =YAML.load(File.read filename)
FileUtils.cp filename, "#{filename}.bak"
use_psych
File.open(filename, 'w'){ |file| file.write(YAML.dump(hash)) }
$stdout.puts " done."end
Convert Syck to Psych YAML format
If you deal with a lot of YAML in your Ruby code, especially migrating from Ruby 1.8.x to 1.9.2 and 1.9.3, then you may have run into some of the numerous issues with YAML incompatibility. I won’t bore you with a lot of specifics, because most of these bugs are transient, but here are the basic facts:
You can check which engine is active in Ruby 1.9.x like so:
Hopefully you are using Psych for everything, but if you have legacy Syck YAML files lying around you could be in for some pain because they are not necessarily compatible. In my case, I had a bunch of i18n translation files emitted with Syck which uses an incompatible escape code structure instead of plain utf-8, thereby rendering the files unreadable by both Psych and humans alike. My solution was a little script utilizing the fact that the engine can be swapped dynamically: