How can I make ruby to_yaml method to store utf8 strings with original signs but not escape sequence?
相关问题
- How to install local library with pip to a conda e
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
- ruby 1.9 wrong file encoding on windows
相关文章
- Ruby using wrong version of openssl
- Difference between Thread#run and Thread#wakeup?
- how to call a active record named scope with a str
- “No explicit conversion of Symbol into String” for
- Segmentation fault with ruby 2.0.0p247 leading to
- How to detect if an element exists in Watir
- uninitialized constant Mysql2::Client::SECURE_CONN
- ruby - simplify string multiply concatenation
Checkout Ya2Yaml at RubyForge.
For Ruby 1.9.3+, this is not a problem: the default YAML engine is Psych, which supports UTF-8 by default.
For Ruby 1.9.2- you need to install the
psych
gem and require it before you require yaml:Alternatively, set the
yamler
as Evgeny suggests (assuming you have installed thepsych
gem):Ruby ships with two YAML engines: syck and psych. Syck is old and not maintained, but it is default in 1.9.2, so one needs to switch to psych. Psych dumps UTF-8 strings in UTF-8.
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: