Bug #13337
closed
Eval and Later Defined Local Variables
Added by faraz (Faraz Yashar) about 7 years ago.
Updated almost 5 years ago.
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.
Files
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?
ko1 (Koichi Sasada) wrote:
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?
Attached is a documentation patch. However, a committer with more knowledge of the internals should probably check to see if it is technically accurate.
jeremyevans0 (Jeremy Evans) wrote:
Attached is a documentation patch.
Seems fine.
A question:
However, local variables set inside the call to +eval+ will not be reflected in the surrounding scope.
Isn't "set" vague a little, between "defined" an "assigned"?
- Status changed from Open to Closed
"local variables assigned inside the call to +eval+" sounds like a just assignment to a local variable defined outside, doesn't it?
nobu (Nobuyoshi Nakada) wrote:
"local variables assigned inside the call to +eval+" sounds like a just assignment to a local variable defined outside, doesn't it?
It could definitely be interpreted that way. I'll reword it to make it more clear. Thanks!
Also available in: Atom
PDF
Like0
Like0Like0Like0Like0Like0Like0Like0