Ruby 1.9 print Array is not Unicode

102 Views Asked by At

Why are puts and print results with Unicode characters not the same:

# encoding: utf-8

puts ['裤']
print ['裤']

裤
["\u88E4"]

even though they are the same when they are not in array?

puts '裤' 
print '裤'

裤
裤

Is it possible to change print so it always prints Unicode?

1

There are 1 best solutions below

7
On

I don't see the difference:

puts ['裤']
# 裤
# => nil
print ['裤']
# ["裤"]=> nil
['裤'].inspect
# => "[\"裤\"]"
RUBY_VERSION
# => "1.9.3"

But I think it was because of :print method prints containment of the array without joining its values together, just dump it. I believe that it uses :inspect to print it out. I can't reproduce it, but you try to execute the following ['裤'].inspect on your system.