module DidYouMean::Experimental::IvarNameCorrection
Constants
- REPLS
Public Class Methods
new(no_method_error)
click to toggle source
Calls superclass method
# File lib/did_you_mean/experimental/ivar_name_correction.rb, line 8 def initialize(no_method_error) super @location = no_method_error.backtrace_locations.first @ivar_names = no_method_error.frame_binding.receiver.instance_variables end
Public Instance Methods
corrections()
click to toggle source
Calls superclass method
# File lib/did_you_mean/experimental/ivar_name_correction.rb, line 15 def corrections super + ivar_name_corrections end
ivar_name_corrections()
click to toggle source
# File lib/did_you_mean/experimental/ivar_name_correction.rb, line 19 def ivar_name_corrections @ivar_name_corrections ||= SpellChecker.new(dictionary: @ivar_names).correct(receiver_name.to_s) end
Private Instance Methods
line(abs_path, lineno)
click to toggle source
# File lib/did_you_mean/experimental/ivar_name_correction.rb, line 34 def line(abs_path, lineno) if REPLS[abs_path] REPLS[abs_path].call elsif File.exist?(abs_path) File.open(abs_path) do |file| file.detect { file.lineno == lineno } end end end
receiver_name()
click to toggle source
# File lib/did_you_mean/experimental/ivar_name_correction.rb, line 25 def receiver_name return unless receiver.nil? abs_path = @location.absolute_path lineno = @location.lineno /@(\w+)*\.#{method_name}/ =~ line(abs_path, lineno).to_s && $1 end