Ruby散列中保存中文,使用puts输出时只能显示unicode码,请问如何显示中文?
源码:
hash={a:"第一条",b:"第二条",c:"第三条"}
puts hash
输出结果:
{:a=>"\u7B2C\u4E00\u6761", :b=>"\u7B2C\u4E8C\u6761", :c=>"\u7B2C\u4E09\u6761"}
怪我咯2017-04-24 09:16:09
Open irb input
Encoding.locale_charmap
Check if your encoding is => "UTF-8"
The Ruby version must be greater than 1.8
Check whether you have readline installed
怪我咯2017-04-24 09:16:09
I tested it on CentOS and Mac and didn’t find the problem you mentioned.