Bug #9926

class_eval : string and block

Added by Sébastien Durand about 1 year ago. Updated about 1 year ago.

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

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 Updated by Shugo Maeda about 1 year 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