Rails Plugins

Work

Convert Syck to Psych YAML format

November 12, 2012

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.

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: