[Bug #616] instance_eval and Module#to_s


#1

Bug #616: instance_eval and Module#to_s
http://redmine.ruby-lang.org/issues/show/616

e$B5/I<<Te(B: Shyouhei U.
e$B%9%F!<%?%9e(B: Open, e$BM%@hEYe(B: Normal
e$BC4Ev<Te(B: Yukihiro M., e$B%+%F%4%je(B: core

e$B0J2<$N$h$&$K!"%/%i%9$NL>A0$,e(B1.8e$B$H0c$&$3$H$,$"$k$h$&$G$9!#e(B

% for i in trunk branches/ruby_1_8; do ~/target/$i/bin/ruby -ve
‘instance_eval{p((C = Class.new).to_s)}’; done
ruby 1.9.0 (2008-10-06 revision 17576) [x86_64-linux]
“#Class:0x000000007c4c50
ruby 1.8.7 (2008-09-23 revision 17572) [x86_64-linux]
“C”


#2

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Roger P.)

which is the preferred way then? :slight_smile:

http://redmine.ruby-lang.org/issues/show/616


#3

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Shyouhei U.)

The latter (1.8 behavior). That one-liner definitely assignes a
Class.new to a constant C
(wherever that constant belongs to), so that assignment should take
effect I think.

http://redmine.ruby-lang.org/issues/show/616


#4

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Akira T.)

1.8 e$B$He(B 1.9 e$B$G!"e(BC e$B$NDj5A@h$,0c$&!#e(B
1.8 e$B$G$O%0%m!<%P%k!#e(B1.9 e$B$G$Oe(B main
e$B$NFC0[%/%i%9$NCf$KDj5A$5$l$k!#e(B

% ./ruby -ve 'instance_eval{p((C = Class.new).to_s)};
class << self
p C
end

ruby 1.9.1 (2008-12-21 revision 20902) [i686-linux]
“#Class:0x825d5c0
#Class:0x825d5c0

1.9 e$B$,@5$7$$e(B?

http://redmine.ruby-lang.org/issues/show/616


#5

In article removed_email_address@domain.invalid,
Akira T. removed_email_address@domain.invalid writes:

1.9 e$B$,@5$7$$e(B?

e$B$&!"$^$A$,$$$G$9!#@5$7$=$&$J$N$Oe(B 1.8 e$B$G$9!#e(B


#6

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Yuki S.)

e$B;d$,$H$j$"$($:8+$F$_$^$9!#<j$KIi$($J$+$C$?$i:{ED$5$s$K?6$j$^$9!#e(B

http://redmine.ruby-lang.org/issues/show/616


#7

e$B!!$5$5$@$G$9!%e(B

Shyouhei U. wrote::

ruby 1.9.0 (2008-10-06 revision 17576) [x86_64-linux]
“#Class:0x000000007c4c50
ruby 1.8.7 (2008-09-23 revision 17572) [x86_64-linux]
“C”

e$B!!$3$l$O!$<!$Ne(B2e$B$D$NLdBj$KJ,$1$i$l$^$9!%e(B

(1) instance_eval{} e$B<B9TCf$NDj?t$NDj5A@he(B
(2) e$BFC0[%/%i%9%3%s%F%-%9%HCf$GDj5A$5$l$?%/%i%9L>e(B

e$B!!e(B(1) e$B$Oe(B 1.9 e$B$NHs8_49!$e(B(2) e$B$Oe(B 1.8
e$B$+$i$"$C$?LdBj$G$9!%e(B

e$B!!e(B(1) e$B$O!$e(Brecv.instance_eval(&b) e$B$N>l9g!$e(B1.8
e$B$G$Oe(B b e$B$N%3%s%F%-%9%H$K1~$8e(B
e$B$FDj?tDj5A@h%3%s%F%-%9%H$,JQ$o$j$^$7$?$,!$e(B1.9 e$B$G$Oe(B recv
e$B$NFC0[%/%i%9%3%se(B
e$B%F%-%9%H$K$J$C$F$7$^$&!$$H$$$&Hs8_49$G$9!%e(B

class C
end

C.instance_eval{
Const = 1
}

p Const #=> 1.8: 1
#=> 1.9: NameError
class << C
p Const #=> 1 # 1.9, 1.8: 1
end

e$B!!e(B(2) e$B$O!$FC0[%/%i%9%3%s%F%-%9%HCf$Ge(B Class.new
e$B$GDj5A$5$l$?%/%i%9L>$O!$e(B
e$BDj?t$KBeF~$5$l$F$bL>A0$,$D$-$^$;$s!%e(B

e$B!!$G!$e(B(1)
e$B$NLdBj$G!$FC0[%/%i%9%3%s%F%-%9%H$GDj5A$5$l$k$N$G!$L>A0$,I=<($5e(B
e$B$l$J$$!$$H$$$&$3$H$K$J$j$^$7$?!%e(B

C = Class.new do
end

class << self
D = Class.new do
$D = self
end
end

p [C, $D] #=> [C, #Class:0x383f2f4]

e$B!!e(B(1)
e$B$K$D$$$F$O!$;EMM$NLdBj$J$N$G$^$D$b$H$5$s$NH=CG$,I,MW$+$H;W$$$^$9!%e(B
(2) e$B$O!$C1$K%P%0$8$c$J$$$+$H;W$$$^$9!%e(B


#8

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

In message “Re: [ruby-dev:37640] Re: [Bug #616] instance_eval and
Module#to_s”
on Mon, 29 Dec 2008 12:38:11 +0900, SASADA Koichi removed_email_address@domain.invalid
writes:

|e$B!!$3$l$O!$<!$Ne(B2e$B$D$NLdBj$KJ,$1$i$l$^$9!%e(B
|
|(1) instance_eval{} e$B<B9TCf$NDj?t$NDj5A@he(B
|(2) e$BFC0[%/%i%9%3%s%F%-%9%HCf$GDj5A$5$l$?%/%i%9L>e(B
|
|e$B!!e(B(1) e$B$Oe(B 1.9 e$B$NHs8_49!$e(B(2) e$B$Oe(B 1.8 e$B$+$i$"$C$?LdBj$G$9!%e(B

|e$B!!e(B(1) e$B$K$D$$$F$O!$;EMM$NLdBj$J$N$G$^$D$b$H$5$s$NH=CG$,I,MW$+$H;W$$$^$9!%e(B

e$B$3$C$A$K$O=q$$$F$^$;$s$G$7$?$,!"e(B(1)e$B$Oe(B1.9e$B$G$N;EMMJQ99$H$7$^$9!#e(B


#9

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Yuki S.)

e$B$3$l$OC1=c$K!“e(Binstance_evale$B$de(Bmodule_evale$B$G$Oe(Bcrefe$B$r@Q$s$8$c$$$1$J$$$H$$$&$3$H$J$s$G$9$,!”:#$Oe(Byield_udere$B$G@Q$`$h$&$K$J$C$F$^$9!#e(B

e$B$3$l$r<h$j=|$/$H:#EY$O%a%=%C%IDj5A@h$,@Z$jBX$o$i$J$$$h$&$G$9!#%9%?%C%/$NA4BNA|$rGD0.$7$F$J$$$s$G$9$,!“Dj?t%9%3!<%W%9%?%C%/$H!”%a%=%C%IDj5A%9%3!<%W%9%?%C%/$,E}9g$5$l$F$^$9$+e(B?

http://redmine.ruby-lang.org/issues/show/616


#10

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Yui NARUSE)

ruby -v ruby 1.9.2dev (2009-10-19 trunk 25399) [x86_64-freebsd7.2]
e$B$K%;%C%He(B

e$B$3$l$Ne(B (2) e$B$C$F7k6I$I$&$9$k$s$G$9$+e(B

http://redmine.ruby-lang.org/issues/show/616


#11

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

In message “Re: [ruby-dev:39521] [Bug #616] instance_eval and
Module#to_s”
on Wed, 21 Oct 2009 19:30:25 +0900, Yui NARUSE
removed_email_address@domain.invalid writes:

|e$B$3$l$Ne(B (2) e$B$C$F7k6I$I$&$9$k$s$G$9$+e(B

e$B$I$&$7$^$7$g$&$M!#5sF0$H$7$F$Oe(B

  • e$BL>A0$,$J$$;~$K$Oe(BObjecte$B$+$iDj?t$r$?$0$C$F%/%i%9$rC5$9e(B
  • e$B8+$D$+$C$?$i!"L>A0$H$7$FEPO?$9$ke(B

e$B$H$$$&?6$kIq$$$r$7$F$$$k$N$G$9$,!“FC0[%/%i%9$K$OL>A0$,$”$j$^e(B
e$B$;$s$+$i!">e5-$NC5:w$G8+$D$+$i$:!"L>A0$,$D$+$J$$$H$$$&$3$H$Ge(B
e$B$9!#$3$l$O$7$g$&$,$J$$5$$,$7$^$9!#$H$$$&$3$H$G!"J|CV$K5$;}$Ae(B
e$B$,79$$$F$^$9!#e(B

e$B0lJ}!"e(Bclasse$BJ8$GDj5A$7$?>l9g$K$Oe(B

#Class:0x8caf000::Foo

e$B$N$h$&$JL>A0$,Dj5A$5$l$A$c$&$o$1$G$9$,!"$3$l$O$3$l$G5$;}$A$,e(B
e$B0-$$$G$9$M$(!#e(B

e$B$3$NJU$b4^$a$F9M$($k$H!"e(B

  • e$B8=:_$NL>A0e(B(e$B%Q%9e(B)e$B$r!"L>A0$H?F$N%Q%9$KJ,N%e(B
  • e$B?F$K%Q%9$,e(B(e$B$^$@e(B)e$B$J$$>l9g!"%Q%9$N@8@.$rCY1de(B

e$B$H$+$b9M$($i$l$J$$$3$H$b$J$$$N$G$9$,!"%3%9%H$K8+9g$&$+$I$&$+!#e(B

                            e$B$^$D$b$He(B e$B$f$-$R$me(B /:|)

#12

e$B%A%1%C%He(B #616 e$B$,99?7$5$l$^$7$?!#e(B (by Yusuke E.)

e$B%9%F!<%?%9e(B Opene$B$+$ie(BClosede$B$KJQ99e(B

e$B1sF#$G$9!#e(B

2008e$BG/e(B12e$B7ne(B29e$BF|e(B12:38 SASADA Koichi removed_email_address@domain.invalid:

% for i in trunk branches/ruby_1_8; do ~/target/$i/bin/ruby -ve ‘instance_eval{p((C = Class.new).to_s)}’; done
(1) e$B$Oe(B 1.9 e$B$NHs8_49!$e(B(2) e$B$Oe(B 1.8 e$B$+$i$"$C$?LdBj$G$9!%e(B
(1) e$B$NHs8_49$Oe(B [ruby-core:26774] e$B$G$Ne(B Yehuda
e$B$N@bF@$K$h$j!"e(B1.8 e$B$Ne(B
e$B5sF0$KLa$5$l$?$H;W$$$^$9!#e(B
e$B$3$l$K$h$C$F!"85$NKNIt$5$s$NLdBj$O$9$G$K2r7h$7$F$$$^$9!#e(B

(2) e$B$NLdBj$Oe(B

o = Object.new
class << o
class C; end
D = Class.new
p [C, D] #=> [#Class:0x825657c::C, #Class:0x82564f0]
end

e$B$NI=<($N0l4S@-$N$J$5$,5$;}$A0-$$$H$$$&$@$1$NOC$@$H;W$$$^$9!#e(B

e$B$3$N%A%1%C%H$@$H2?$,LdBj$+$o$+$j$K$/$$$N$G!"$3$N%A%1%C%H$O0lC6JD$8!"e(B
e$B?7$7$/%A%1%C%H$r:n$j$?$$$H;W$$$^$9!#e(B


Yusuke ENDOH removed_email_address@domain.invalid

http://redmine.ruby-lang.org/issues/show/616