Useful resources for using YAML in Ruby

April 13th, 2007 at 3:46 pm

As I mentioned here, I had a choice of using either XML or YAML for the configuration files in the new version of ESMS. YAML won for two reasons:

  1. It is much more lightweight and looks natural. Big configuration files in XML become complex and cluttered, while YAML scales admirably in this respect.
  2. The current de-facto XML implementation in Ruby is REXML, which I dislike. REXML is useful for employing XML as a serialization format, but is less good as a configuration file reader, because its error handling is very bad. On the other hand, Syck (the built-in YAML parser / emitter in Ruby) is easy to use, fast and has good error handling and reporting.

The following are good resources for YAML in Ruby:

  1. Yaml cookbook - shows probably all you’ll ever need to understand how Yaml entities map to Ruby code. Very useful.
  2. Yaml.rb docs - A reference manual with examples for the Yaml.rb library.
  3. YAML specification - from the official YAML website (yaml.org). A crisp yet well written reference to the YAML syntax and semantics.

Related posts:

  1. JSON is YAML, but YAML is not JSON
  2. XML or YAML for configuration files
  3. Book review: “Ruby Cookbook” by L. Carlson and L. Richardson
  4. Book review: “The Ruby way” by Hal Fulton
  5. Book review: “Programming Ruby, 2nd Ed.” by Dave Thomas and Andy Hunt

Leave a Reply

To post code with preserved formatting, enclose it in `backticks` (even multiple lines)