views:

636

answers:

2

How can I make ruby to_yaml method to store utf8 strings with original signs but not escape sequence?

+2  A: 

This is probably a really bad idea as I'm sure YAML has its reasons for encoding the characters as it does, but it doesn't seem too hard to undo:

require 'yaml'
require 'yaml/encoding'

text = "Ça va bien?"

puts text.to_yaml(:Encoding => :Utf8) # => --- "\xC3\x87a va bien?"
puts YAML.unescape(YAML.dump(text)) # => --- "Ça va bien?"
tadman
+2  A: 

Checkout Ya2Yaml at RubyForge.

Joost