From: nobu@... Date: 2015-12-08T15:44:12+00:00 Subject: [ruby-core:71950] [Ruby trunk - Feature #11777] Change NameError#local_variables to return the list of local variables where the method is raised Issue #11777 has been updated by Nobuyoshi Nakada. Yes, this method is only for did_you_mean gem. ---------------------------------------- Feature #11777: Change NameError#local_variables to return the list of local variables where the method is raised https://bugs.ruby-lang.org/issues/11777#change-55359 * Author: Yuki Nishijima * Status: Closed * Priority: Normal * Assignee: ---------------------------------------- Sasada-san and I talked about this briefly a few weeks ago, but I also wanted to let others know about this. This change will make it possible to pull out the list of local variables where the exception is raised without TracePoint. The `did_you_mean` gem uses TracePoint, and the current code looks like this: ```ruby # lib/did_you_mean.rb TracePoint.new(:raise) do |tp| e = tp.raised_exception if SPELL_CHECKERS.include?(e.class.to_s) && !e.instance_variable_defined?(:@frame_binding) e.instance_variable_set(:@frame_binding, tp.binding) end end.enable # lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb def initialize(exception) ... @lvar_names = exception.frame_binding.local_variables ... end ``` If we change `NameError#local_variables` as described it'll look like this: ```ruby # lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb def initialize(exception) @lvar_names = exception.local_variables ... end ``` The problem with TracePoint is that it's still a little buggy (also see #11668, #11667) and also makes Ruby slower [as reported by Sasada-san](https://twitter.com/_ko1/status/657599422566543360). I would like to change the behaviour of `NameError#local_variables` and remove the use of TracePoint from the gem entirely so we can make the gem much more stable. -- https://bugs.ruby-lang.org/