Project

General

Profile

Bug #13337

Eval and Later Defined Local Variables

Added by faraz (Faraz Yashar) about 2 years ago. Updated almost 2 years ago.

Status:
Open
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:80253]

Description

I've noticed the following behavior with eval:

def example
  eval("foo") # => nil, but would expect a NameError
  eval("bar") # => NameError
  foo = 1
end

I'm assuming this behavior is expected, since "eval" executes in the context of the existing YARV instructions and local table, but I'm not certain since I haven't seen this behavior documented anywhere.

History

Updated by ko1 (Koichi Sasada) almost 2 years ago

This is specification.

(1) parse example method and define foo.
(2) In eval method, compile given string ("foo") and defined foo was used (without any problem).

So it is documentation issue.
Can anyone write about it?

Also available in: Atom PDF