From: Koichi Sasada <redmine@...>
Date: 2012-03-11T16:56:00+09:00
Subject: [ruby-dev:45332] [ruby-trunk - Bug #5689][Rejected] class variables inside of instance methods inside of "class_eval"


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 Urabe
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



-- 
http://bugs.ruby-lang.org/