Issue #13337 has been updated by jeremyevans0 (Jeremy Evans). File doc-eval-local-var.patch added 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. ---------------------------------------- Bug #13337: Eval and Later Defined Local Variables https://bugs.ruby-lang.org/issues/13337#change-78847 * Author: faraz (Faraz Yashar) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.4.0 * Backport: 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN ---------------------------------------- I've noticed the following behavior with eval: ~~~ ruby 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-------------------------------- doc-eval-local-var.patch (1.63 KB) -- https://bugs.ruby-lang.org/ Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe> <http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>