From: "zverok (Victor Shepelev) via ruby-core" Date: 2024-12-23T06:19:02+00:00 Subject: [ruby-core:120374] [Ruby master Bug#20965] `it` vs `binding.local_variables` 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/