Project

General

Profile

Bug #9926

class_eval : string and block

Added by Sébastien Durand about 2 years ago. Updated about 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
ruby -v:
ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-linux]
[ruby-core:63065]

Description

I'm not sure, is this a bug or a feature ?

class Foo; @@bar = 'bar'; end
p Foo.class_eval('@@bar') # => "bar"
p Foo.class_eval { @@bar } => uninitialized class variable @@bar in Object (NameError)

History

#1 [ruby-core:63094] Updated by Shugo Maeda about 2 years ago

  • Status changed from Open to Closed

Sébastien Durand wrote:

I'm not sure, is this a bug or a feature ?

class Foo; @@bar = 'bar'; end
p Foo.class_eval('@@bar') # => "bar"
p Foo.class_eval { @@bar } => uninitialized class variable @@bar in Object (NameError)

It's not a bug, but an expected behavior.
The block version of class_eval doesn't affect class variable and constant lookup.

Also available in: Atom PDF