[Feature #3328] Kernel#p outputs as default_internal encoding, and so on

Feature #3328: Kernel#p outputs as default_internal encoding, and so on
http://redmine.ruby-lang.org/issues/show/3328

e$B5/I<<Te(B: Masaya T.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$B%+%F%4%je(B: core, Target version: 1.9.x

e$BC.2H$G$9!#e(B

Feature #2102 [ruby-dev:39343]
e$B$Ge(BString#inspecte$B$K$D$$$F$O6/@)E*$Ke(Bencodinge$B$rB7$($k$h$&$K$J$j$^$7$?$,!"e(BSymbole$B$de(BRegexpe$B$K$D$$$F$O$=$&$J$C$F$*$i$:!"F1$8$h$&$J4JC1$K%(%i!<$K$J$k>uBV$K$J$C$F$$$^$9!#%f!<%6!<Dj5A$Ne(Binspecte$B$K$bF1MM$G$9!#$^$?$Ke(Binspecte$B$GJ8;z%3!<%I$N0c$$$,6hJL$G$-$^$;$s!#e(B

e$B$=$3$G!"e(BKernel#pe$B$GI=<($9$kA0$de(BArraye$B$de(BHashe$B$G3Fe(Binspecte$B7k2L$r%^!<%8$9$kA0$K!"e(BString#inspecte$B$HF1MM$J=hM}$r9T$&$N$O$I$&$G$7$g$&$+!)6qBNE*$K$Oe(Binspecte$B$GA[Dj$9$ke(BEncodinge$B$H0[$J$k>l9g$K!“Hse(BASCIIe$BJ8;z$r%(%9%1!<%WI=<($K$9$ke(BString#inspect_encodee$B$rDI2C$7!”$=$l$re(Brb_inspecte$B$+$i8F$V;v$rDs0F$7$?$$$H;W$$$^$9!#e(BASCIIe$BJ8;z$K$D$$$F$O<j$r2C$($J$$$?$a!"IT2D5U$G$9$,e$OLdBj$J$$$H;W$$$^$9!#e(B
e$B$48!F$$r$*4j$$$7$^$9!#e(B

e$B0J2<$K8=>u$HDs0F8e$N7k2L!"e(BKernel#pe$B$NDj5A$NJQ99$r<($7$^$9!#e(B
e$B$^$?$3$NJQ99$r9T$&e(Bpatche$B$rE:IU$7$^$9!#e(B

cat inspect.rb

-- encoding: utf-8 --

Encoding.default_external = “WINDOWS-31J”
STDOUT.set_encoding “WINDOWS-31J”
a = "e$B$“e(B”
su = a.intern
se = a.encode(“euc-jp”).intern
sw = a.encode(“windows-31j”).intern
ru= /#{a}/
re= /#{a.encode(“euc-jp”)}/
rw= /#{a.encode(“windows-31j”)}/
hash = { su => se }
p su,se,sw,ru,re,rw
p hash rescue p $!
p [ru,re,rw,su,se,sw] rescue p $!

ruby_org inspect.rb
:e$B$"e(B
:e$B$"e(B
:e$B$"e(B
/e$B$"e(B/
/e$B$"e(B/
/e$B$"e(B/
#<Encoding::CompatibilityError: incompatible character encodings: UTF-8
and EUC-JP>
#<Encoding::CompatibilityError: incompatible character encodings: UTF-8
and EUC-JP>

ruby_new inspect.rb
:\u3042
:\x{A4A2}
:e$B$"e(B
/\u3042/
/\x{A4A2}/
/e$B$"e(B/
{:\u3042=>:\x{A4A2}}
[/\u3042/, /\x{A4A2}/, /e$B$"e(B/, :\u3042, :\x{A4A2}, :e$B$"e(B]

e$B$^$?!"e(B
Encoding.default_external = “WINDOWS-31J”
STDOUT.set_encoding “WINDOWS-31J”
class A ;def inspect ; "e$B$“e(B”.encode(“euc-jp”) end ; end
p A.new
puts A.new.inspect
puts A.new.inspect.inspect_encode
e$B$N7k2L$,e(B
\x{A4A2}
e$B$"e(B
\x{A4A2}
e$B$H$J$j!"e(Bpe$B$NDj5A$,>/$7JQ$o$j$^$9!#e(B

e$B@.@%$G$9!#e(B

(2010/05/21 8:10), Masaya T. wrote:

Feature #2102 [ruby-dev:39343] e$B$Ge(BString#inspecte$B$K$D$$$F$O6/@)E*$Ke(Bencodinge$B$re(B
e$BB7$($k$h$&$K$J$j$^$7$?$,!"e(BSymbole$B$de(BRegexpe$B$K$D$$$F$O$=$&$J$C$F$*$i$:!"e(B
e$BF1$8$h$&$J4JC1$K%(%i!<$K$J$k>uBV$K$J$C$F$$$^$9!#%f!<%6!<Dj5A$Ne(Binspecte$B$K$be(B
e$BF1MM$G$9!#$^$?$Ke(Binspecte$B$GJ8;z%3!<%I$N0c$$$,6hJL$G$-$^$;$s!#e(B

Symbol e$B$He(B Regexp e$B$OK:$l$F$$$^$7$?!#e(B
e$B3N$+$KBP=h$,I,MW$@$H;W$$$^$9!#e(B

e$B$=$3$G!"e(BKernel#pe$B$GI=<($9$kA0$de(BArraye$B$de(BHashe$B$G3Fe(Binspecte$B7k2L$r%^!<%8$9$kA0$K!"e(B
String#inspecte$B$HF1MM$J=hM}$r9T$&$N$O$I$&$G$7$g$&$+!)6qBNE*$K$Oe(Binspecte$B$Ge(B
e$BA[Dj$9$ke(BEncodinge$B$H0[$J$k>l9g$K!“Hse(BASCIIe$BJ8;z$r%(%9%1!<%WI=<($K$9$ke(B
String#inspect_encodee$B$rDI2C$7!”$=$l$re(Brb_inspecte$B$+$i8F$V;v$rDs0F$7$?$$$He(B
e$B;W$$$^$9!#e(BASCIIe$BJ8;z$K$D$$$F$O<j$r2C$($J$$$?$a!"IT2D5U$G$9$,e$OLdBje(B
e$B$J$$$H;W$$$^$9!#e(B e$B$48!F$$r$*4j$$$7$^$9!#e(B

e$BF1MM$J=hM}$H$$$$$J$,$i$J$<?7$7$$e(B API e$B$rDI2C$9$k$s$G$9$+!#e(B

e$BC.2H$G$9!#e(B

2010e$BG/e(B5e$B7ne(B24e$BF|e(B21:18 NARUSE, Yui [email protected]:

NARUSE, Yui [email protected]

e$BF1MM$J=hM}$H$$$$$J$,$i$J$<?7$7$$e(B API e$B$rDI2C$9$k$s$G$9$+!#e(B

Featuree$B$J$N$G!";dE*$K;W$$@Z$C$F$I$&=hM}$7$?$iM}A[E*$@$m$&$H9M$($?7k2L$G$9!#e(B
e$BF1MM$J=hM}e(B=inspect_encodee$B$G$9$,!"7k6Ie(BSymbole$B7?$de(BRegexpe$B7?$K8B$i$:e(B
e$BI,MW$K$J$j$=$&$J$N$GJ,N%$7$?$$$H;W$$$^$7$?!#e(B

e$B$3$l$rF3F~$7$?>l9g!"85$Ne(BString#Inspecte$B$re(B
String#old_Inspecte$B$H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H$$$&H=CG$O@h$N%a!<%k$K=q$$$?$h$&$K!”$=$l$O$=$l$G$"$j$G$9!#e(B

e$B$?$@$7!"%f!<%6!<$,e(BArraye$B$NMM$J!“FbIt$Ge(Binspecte$B$r8F$V%/%i%9$Ne(Binspcete$B$r=q$/$H$-$K$Oe(BEncodinge$B$K8_49@-$,L5$$$H5/$3$i$l$ke(B
e$B2DG=@-$,$”$k8B$j$OI,MW$JJQ49$G$9$7!"8x3+$7$?J}$,$&$l$7$$?M$,B?$$$N$G$O$J$$$H;W$$$^$9!#e(B

e$B<:GT$;$:$K$J$s$i$+$7$i$N7A$GBP>]e(Bencodinge$B$KJQ49$7$F$/$l$k4JJX$Je(BAPIe$B$,L5$$$H$$$&8=>u$Ne(Bencodinge$B4D6-$Oe(Bstricte$B$G$9$,!"e(B
e$B%W%m%0%i%`$7$F$$$F<g$K%G%P%C%/$G?I$$$G$9!#e(B

e$B$^$D$b$He(B e$B$f$-$R$m$G$9e(B

In message “Re: [ruby-dev:41482] Re: [Feature #3328] Kernel#p outputs as
default_internal encoding, and so on”
on Mon, 31 May 2010 19:16:38 +0900, Masaya TARUI [email protected]
writes:

|e$BC.2H$G$9!#e(B

|> e$BF1MM$J=hM}$H$$$$$J$,$i$J$<?7$7$$e(B API e$B$rDI2C$9$k$s$G$9$+!#e(B
|
|Featuree$B$J$N$G!";dE*$K;W$$@Z$C$F$I$&=hM}$7$?$iM}A[E*$@$m$&$H9M$($?7k2L$G$9!#e(B
|e$BF1MM$J=hM}e(B=inspect_encodee$B$G$9$,!"7k6Ie(BSymbole$B7?$de(BRegexpe$B7?$K8B$i$:e(B
|e$BI,MW$K$J$j$=$&$J$N$GJ,N%$7$?$$$H;W$$$^$7$?!#e(B

e$B7kO@$,$J$$$N$G?=$7Lu$J$$$N$G$9$,!“e(Bencodinge$B=hM}$NM}A[$O6u5$$Ne(B
e$B$h$&$K8+$($J$$$3$H$G!”$$$D$+$N>-Mhe(BUnicodee$B$,@$3&@)GF$7$?;~$K<Be(B
e$B8=$5$l$k$N$@$H;W$$$^$9e(B(e$B<B8=$9$k$N$G$"$l$Pe(B)e$B!#$G!“2>$K$3$Ne(BAPIe$B$,e(B
e$B$=$N:”$^$G;D$C$?$H$9$k$H!"LUD2$N$h$&$KITMW$J$b$N$K$J$k$3$H$,e(B
e$BM=A[$5$l$^$9!#$=$l$Oe(BAPIe$B%G%6%$%s$H$7$F6Z$,0-$$$N$G$O$J$$$G$7$ge(B
e$B$&$+!#e(B