Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
为什么puts和print使用 Unicode 字符的结果不一样:
puts
print
# encoding: utf-8 puts ['裤'] print ['裤'] 裤 ["\u88E4"]
即使它们不在数组中时它们是相同的?
puts '裤' print '裤' 裤 裤
是否有可能改变print它总是打印Unicode?
我看不出有什么区别:
puts ['裤'] # 裤 # => nil print ['裤'] # ["裤"]=> nil ['裤'].inspect # => "[\"裤\"]" RUBY_VERSION # => "1.9.3"
但我认为这是因为:print方法打印包含数组而不将其值连接在一起,只是转储它。我相信它:inspect用来打印出来。我无法重现它,但您尝试['裤'].inspect在您的系统上执行以下操作。
:print
:inspect
['裤'].inspect