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) # => --- "xC3x87a va bien?"
puts YAML.unescape(YAML.dump(text)) # => --- "Ça va bien?"
这篇关于Ruby to_yaml utf8 字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文