Issue #12042 has been updated by Yuki Nishijima.


As you may know, in Ruby 2.2 and older, `#local_variables` returns a list of local variables available in the scope where the method is called, or raises an NameError if it's called from outside of the class:

```ruby
class NameError
  def call_local_variables
    foo = bar = nil
    local_variables
  end
end

the_value = nil

begin
  doesnt_exist
rescue => e
  # Ruby 2.2 and older
  e.local_variables      # => NoMethodError: private method `local_variables' called...
  e.call_local_variables # => [:foo, :bar]
end
```

We've changed it to behave like the following:

```ruby
... # same setup

begin
  doesnt_exist
rescue => e
  # Ruby 2.3 (current)
  e.local_variables      # => [:the_value]
  e.call_local_variables # => [:the_value]
end
```

And an example of what I would like to add/change would be something like:

```ruby
... # same setup

begin
  doesnt_exist
rescue => e
  # Ruby 2.4
  e.local_variables      # => NoMethodError: private method `local_variables' called...
  e.call_local_variables # => [:foo, :bar]
  e.something_new        # => [:the_value]
end
```

----------------------------------------
Feature #12042: A better interface that returns a list of local variables available where the exception is raised
https://bugs.ruby-lang.org/issues/12042#change-56839

* Author: Yuki Nishijima
* Status: Feedback
* Priority: Normal
* Assignee: 
----------------------------------------
We've changed the behavior of `NameError#local_variables` as discussed on #11777, but I'm not actually satisfied by the change. This change has made it impossible to get a list of local variables available within a NameError scope. It would be nice, if we could add a new method that does what `NameError#local_variables` does right now, and change the `local_variables` method back to the previous behavior.

I actually don't have a good name in mind, but please let me know if anyone has a good name for it.



-- 
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>