From: Carlos Date: 2004-06-05T02:23:45+09:00 Subject: Re: utf8 strings and inspect [Benny , 2004-06-04 18.53 CEST] > if I have an utf8-string > > utf8str = "���" > > then Object#inspect gives me > > utf8str.inspect #=> "\303\244\303\266\303\274" > > but String#to_s gives me > > utf8str.to_s #=> "���" > > even if the documentation says that Object#inspect uses .to_s to convert an > object to a string. > > even funnier, in the irb (I guess that is, because the irb uses > Object#inspect for the output) > > irb(main):010:0>utf8str.to_s > => "\303\244\303\266\303\274" > irb(main):010:0>utf8str.inspect > => "\"\\303\\244\\303\\266\\303\\274\"" > > so how can I change Object#inspect to use String#to_s ? You don't need to. Just tell ruby that you are working with UTF-8 and not ASCII, and it will not escape the non-ASCII bytes in the output. irb(main):001:0> utf8str="���" => "\303\244\303\266\303\274" irb(main):002:0> $KCODE='u' => "u" irb(main):003:0> utf8str => "���" irb(main):004:0> utf8str.inspect => "\"���\""