Project

General

Profile

Actions

Bug #9926

closed

class_eval : string and block

Added by Anonymous almost 10 years ago. Updated almost 10 years ago.

Status:
Closed
Assignee:
-
Target version:
-
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)

Updated by shugo (Shugo Maeda) almost 10 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.

Actions

Also available in: Atom PDF

Like0
Like0