Search
Categories
Ad

Dump YAML Strings with UTF-8 multibyte characters in Ruby

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

Tags: ,

One Response to “Dump YAML Strings with UTF-8 multibyte characters in Ruby”

  1. anonimo says:

    Thanks a lot!!!!
    I have been looking it during 4 hours!!!

Leave a Reply