[ruby-trunk - Bug #5689][Open] class variables inside of instance methods inside of "class_eval"

Issue #5689 has been reported by Shyouhei U…


Bug #5689: class variables inside of instance methods inside of
“class_eval”
http://redmine.ruby-lang.org/issues/5689

Author: Shyouhei U.
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2011-11-30 trunk 33904) [x86_64-linux]

インスタンスメソッドの中から他のクラスのクラス変数が見えるというのはいかにもまずそうに思うのですが、以下の挙動は意図的ですか。

zsh % ~/target/trunk/bin/ruby -ve’
class Klass
@@cvar = “Klass”
end

Klass.module_eval do
def cvar
@@cvar
end
end

@@cvar = “main”
puts Klass.new.cvar’

ruby 2.0.0dev (2011-11-30 trunk 33904) [x86_64-linux]
-e:12: warning: class variable access from toplevel
-e:8: warning: class variable access from toplevel
main

Issue #5689 has been updated by Shugo M…

Shyouhei U. wrote:

end
end

@@cvar = “main”
puts Klass.new.cvar’

module_evalは定数同様にクラス変数の探索にも影響しないので、意図的では
あるんじゃないでしょうか。
定数探索の動作を1.8と同じに戻した時の議論で、クラス変数をどうするかも
議論した上で、合わせて1.8の動作に戻したように記憶しています。

ただ、今の動作が望ましいかどうかは議論の余地があると思います。


Bug #5689: class variables inside of instance methods inside of
“class_eval”
http://redmine.ruby-lang.org/issues/5689

Author: Shyouhei U.
Status: Open
Priority: Normal
Assignee:
Category: core
Target version: 2.0.0
ruby -v: ruby 2.0.0dev (2011-11-30 trunk 33904) [x86_64-linux]

インスタンスメソッドの中から他のクラスのクラス変数が見えるというのはいかにもまずそうに思うのですが、以下の挙動は意図的ですか。

zsh % ~/target/trunk/bin/ruby -ve’
class Klass
@@cvar = “Klass”
end

Klass.module_eval do
def cvar
@@cvar
end
end

@@cvar = “main”
puts Klass.new.cvar’

ruby 2.0.0dev (2011-11-30 trunk 33904) [x86_64-linux]
-e:12: warning: class variable access from toplevel
-e:8: warning: class variable access from toplevel
main

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

In message “Re: [ruby-dev:44907] [ruby-trunk - Bug #5689] class
variables inside of instance methods inside of “class_eval””
on Wed, 30 Nov 2011 13:14:05 +0900, Shugo M.
[email protected] writes:

|module_eval$B$ODj?tF1MM$K%/%i%9JQ?t$NC5:w$K$b1F6A$7$J$$$N$G!“0U?^E*$G$O(B
|$B$”$k$s$8$c$J$$$G$7$g$&$+!#(B
|$BDj?tC5:w$NF0:n$r(B1.8$B$HF1$8$KLa$7$?;[email protected]$G!"%/%i%9JQ?t$r$I$&$9$k$+$b(B
|[email protected]$7$?>e$G!"9g$o$;$F(B1.8$B$NF0:n$KLa$7$?$h$&$K5-21$7$F$$$^$9!#(B

$B0U?^E*$G$9!#$N$G!"$3$l$O>/$J$/$H$b%P%0$G$O$"$j$^$;$s!#(B

|[email protected]!":#$NF0:n$,K>$^$7$$$+$I$&[email protected]$NM>CO$,$"$k$H;W$$$^$9!#(B

$B$=$&$G$9$M!#!V(Bmodule_eval$B$ODj?t(B($B$d%/%i%9JQ?t(B)$B$NC5:[email protected]$rJQ$($F(B
$B$7$^$C$?$[$&$,NI$$!W$H$$$&9M$($OEvA3$"$j$($k$H;W$$$^$9$7!"<B(B
$B:]$K$=$&4|BT$7$F$$$k?M$b$=$l$J$j$K$$$k$h$&$G$9!#(B

$B$=$N$h$&$K5"[email protected]$H9M$($k>l9g$K$O(Bfeature proposal$B$H$7$FDs(B
$B0F$7$F$/[email protected]$5$$!#(B

Issue #5689 has been updated by Koichi Sasada.

Status changed from Open to Rejected


Bug #5689: class variables inside of instance methods inside of
“class_eval”
https://bugs.ruby-lang.org/issues/5689

Author: Shyouhei U.
Status: Rejected
Priority: Normal
Assignee:
Category: core
Target version: 2.0.0
ruby -v: -

インスタンスメソッドの中から他のクラスのクラス変数が見えるというのはいかにもまずそうに思うのですが、以下の挙動は意図的ですか。

zsh % ~/target/trunk/bin/ruby -ve’
class Klass
@@cvar = “Klass”
end

Klass.module_eval do
def cvar
@@cvar
end
end

@@cvar = “main”
puts Klass.new.cvar’

ruby 2.0.0dev (2011-11-30 trunk 33904) [x86_64-linux]
-e:12: warning: class variable access from toplevel
-e:8: warning: class variable access from toplevel
main

$BA0ED$G$9!#(B

2011$BG/(B11$B7n(B30$BF|(B15:01 Yukihiro M. [email protected]:

|[email protected]!":#$NF0:n$,K>$^$7$$$+$I$&[email protected]$NM>CO$,$"$k$H;W$$$^$9!#(B

$B$=$&$G$9$M!#!V(Bmodule_eval$B$ODj?t(B($B$d%/%i%9JQ?t(B)$B$NC5:[email protected]$rJQ$($F(B
$B$7$^$C$?$[$&$,NI$$!W$H$$$&9M$($OEvA3$"$j$($k$H;W$$$^$9$7!"<B(B
$B:]$K$=$&4|BT$7$F$$$k?M$b$=$l$J$j$K$$$k$h$&$G$9!#(B

$B$=$N$h$&$K5"[email protected]$H9M$($k>l9g$K$O(Bfeature proposal$B$H$7$FDs(B
$B0F$7$F$/[email protected]$5$$!#(B

$B$?$V$s(Bwycats$B$,H?BP$9$k$H;W$&$N$G!"(Bfeature
proposal$B$O(Bruby-core$B$K(B
$B=P$7$F$b$i$C$?J}$,$h$$$H;W$$$^$9!#(B

$B8D?ME*$K$O!“Dj?t$O8=:_$N$^$^$G!”%/%i%9JQ?t$O(Bmodule_eval$B$J$I$N(B
$B1F6A$r<u$1$k!"$H$$$&@~$O%"%j$+$J$H$$$&5$$,$7$^$9!#(B
$B%/%i%[email protected]*%9%3!<%W$C$]$$5sF0$r5a$a$k?M$O$"$^$j$$$J$$$H(B
$B;W$$$^$9$N$G!#(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs