Ruby to_yaml utf8字符串 [英] Ruby to_yaml utf8 string
本文介绍了Ruby to_yaml utf8字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使ruby to_yaml方法存储带有原始符号但不转义序列的utf8字符串?
How can I make ruby to_yaml method to store utf8 strings with original signs but not escape sequence?
推荐答案
这可能是一个非常糟糕的主意,因为我敢肯定YAML有其编码字符的原因,但似乎并不难撤消:
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?"
这篇关于Ruby to_yaml utf8字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文