Project

General

Profile

Feature #11777

Change NameError#local_variables to return the list of local variables where the method is raised

Added by yuki24 (Yuki Nishijima) almost 4 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
[ruby-core:71855]

Description

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:

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

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

Associated revisions

Revision 506b25aa
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52942 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 52942
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

Revision 52942
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

Revision 52942
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

Revision 52942
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

Revision 52942
Added by nobu (Nobuyoshi Nakada) almost 4 years ago

error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

History

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

Do you want to add NameError#local_variables?

Updated by matz (Yukihiro Matsumoto) almost 4 years ago

It's OK to add. But I think we should mark it as 'internal use' in the reference.

Matz.

#3

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

  • Status changed from Open to Closed

Applied in changeset r52942.


error.c: name_err_local_variables

  • error.c (name_err_local_variables): new method NameError#local_variables for internal use only. [Feature #11777]

Updated by znz (Kazuhiro NISHIYAMA) almost 4 years ago

NEWS does not mention about this feature.
Is it intended?

Updated by nobu (Nobuyoshi Nakada) almost 4 years ago

Yes, this method is only for did_you_mean gem.

Also available in: Atom PDF