ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: teslur@gmail.com
To: ruby-core@ruby-lang.org
Subject: [ruby-core:95332] [Ruby master Bug#16251] Evaluation in binding differs from ruby execution
Date: Tue, 15 Oct 2019 13:19:40 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-16251.20191015131939.1a6b45bf2078bbe4@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-16251.20191015131939@ruby-lang.org

Issue #16251 has been reported by teslur (Tetsushi FUKABORI).

----------------------------------------
Bug #16251: Evaluation in binding differs from ruby execution
https://bugs.ruby-lang.org/issues/16251

* Author: teslur (Tetsushi FUKABORI)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.6.2p47 (2019-03-13 revision 67232) [x86_64-darwin18]
* Backport: 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
In specific situation, I found that result of string evaluation in Binding returns different from ruby execution result.

In following sample code, ruby evaluates `method_or_local_var` as method call and returns `"method"`.
However, `binding.eval` evaluates `method_or_local_var` as local variable and returns `nil`.

Here is sample code.
```
def method_or_local_var
  'method'
end

if true
  puts "execute method_or_local_var:"
  p method_or_local_var #=> "method"

  puts "execute method_or_local_var by bind.eval('method_or_local_var'):"
  p binding.eval('method_or_local_var') #=> nil
else
  method_or_local_var = 'local variable'
end
```

and here is results of execute sample code.
```
❯ ruby sample_code.rb
execute method_or_local_var:
"method"
execute method_or_local_var by bind.eval('method_or_local_var'):
nil
```

I expect evaluation result of `method_or_local_var` in binding to be method, and returns `"method"`.
Is this the expected behavior?



-- 
https://bugs.ruby-lang.org/

       reply	other threads:[~2019-10-15 13:19 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <redmine.issue-16251.20191015131939@ruby-lang.org>
2019-10-15 13:19 ` teslur [this message]
2019-10-15 13:48 ` [ruby-core:95333] [Ruby master Bug#16251] Evaluation in binding differs from ruby execution mame
2019-10-15 20:27 ` [ruby-core:95347] " eregontp
2019-10-24  2:37 ` [ruby-core:95525] " xkernigh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-16251.20191015131939.1a6b45bf2078bbe4@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).