Project

General

Profile

Actions

Bug #5689

closed

class variables inside of instance methods inside of "class_eval"

Added by shyouhei (Shyouhei Urabe) about 13 years ago. Updated almost 13 years ago.

Status:
Rejected
Assignee:
-
Target version:
ruby -v:
-
Backport:
[ruby-dev:44906]

Description

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

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

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0