From: "zverok (Victor Shepelev) via ruby-core" <ruby-core@ml.ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Cc: "zverok (Victor Shepelev)" <noreply@ruby-lang.org>
Subject: [ruby-core:120374] [Ruby master Bug#20965] `it` vs `binding.local_variables`
Date: Mon, 23 Dec 2024 06:19:02 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-111151.20241223061902.710@ruby-lang.org> (raw)
In-Reply-To: <redmine.issue-20965.20241218195830.710@ruby-lang.org>
Issue #20965 has been updated by zverok (Victor Shepelev).
Interestingly, numbered block parameters do this:
```ruby
"foo".tap do
_1
"bar".tap do
p binding.local_variables #=> [_1]
eval("_1") # undefined local variable or method '_1' for main:Object (NameError)
end
end
```
I am not saying this is good behavior, though. The things I am concerned about (after the release, of course):
1. Whatever the behavior is, it is deliberate and documented;
2. Whatever the behavior is, it is internally consistent (e.g., in #20955 the thing that surprised me was an inconsistency between proc and lambda);
3. Whatever the behavior is, I’d expect it to be as consistent as possible between `it` and numbered anonymous parameters.
(About the latter one: `it`s behavior, after the change is reverted, actually seems more internally consistent at least between `local_variables` and `eval`, so maybe numbered parameters should follow?)
----------------------------------------
Bug #20965: `it` vs `binding.local_variables`
https://bugs.ruby-lang.org/issues/20965#change-111151
* Author: zverok (Victor Shepelev)
* Status: Open
* ruby -v: ruby 3.4.0dev (2024-12-15T13:36:38Z master 366fd9642f) +PRISM [x86_64-linux]
* Backport: 3.1: DONTNEED, 3.2: DONTNEED, 3.3: DONTNEED
----------------------------------------
`it` is not available in the list of `binding.local_varaibles`, **unlike** numbered parameters:
```ruby
p(proc { binding.local_variables }.call) # []
p(proc { |x| binding.local_variables }.call) # [:x]
p(proc { _1; binding.local_variables }.call) # [:_1]
p(proc { vars = binding.local_variables; _1; vars }.call) # [:_1, :vars]
p(proc { it; binding.local_variables }.call) # []
```
I wonder if it is deliberate or accidental.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/lists/ruby-core.ml.ruby-lang.org/
next prev parent reply other threads:[~2024-12-23 6:19 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-18 19:58 [ruby-core:120303] " zverok (Victor Shepelev) via ruby-core
2024-12-19 0:41 ` [ruby-core:120308] " shan (Shannon Skipper) via ruby-core
2024-12-19 6:28 ` [ruby-core:120317] " nobu (Nobuyoshi Nakada) via ruby-core
2024-12-19 9:33 ` [ruby-core:120326] " tompng (tomoya ishida) via ruby-core
2024-12-23 3:37 ` [ruby-core:120369] " mame (Yusuke Endoh) via ruby-core
2024-12-23 4:55 ` [ruby-core:120372] " k0kubun (Takashi Kokubun) via ruby-core
2024-12-23 6:19 ` zverok (Victor Shepelev) via ruby-core [this message]
2024-12-23 8:52 ` [ruby-core:120375] " mame (Yusuke Endoh) via ruby-core
2025-01-09 12:03 ` [ruby-core:120574] " mame (Yusuke Endoh) via ruby-core
2025-01-20 9:47 ` [ruby-core:120744] " mame (Yusuke Endoh) via ruby-core
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-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-111151.20241223061902.710@ruby-lang.org \
--to=ruby-core@ml.ruby-lang.org \
--cc=noreply@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 NNTP newsgroup(s).