Search
Categories
Ad

Posts Tagged ‘yaml’

Dump YAML Strings with UTF-8 multibyte characters in Ruby

Tuesday, June 16th, 2009

Problem

You want to dump your Ruby object to YAML-formatted file, but your object contains UTF-8 multibyte characters. In this situation, original yaml dumper will output in a human-unfriendly format like

  - !binary |
   5a6X6LC35bKs

Solution

The easiest way to solve is to use ya2yaml.

 sudo gem install ya2yaml

Then, in your source code,

open("save.yml", "w") do |f| 
 f.write multiByteObj.ya2yaml
end