/usr/lib/ruby/vendor_ruby/did_you_mean/extra_features/ivar_name_correction.rb is in ruby-did-you-mean 1.0.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 | module DidYouMean
module ExtraFeatures
module IvarNameCorrectable
REPLS = {
"(irb)" => -> { Readline::HISTORY.to_a.last }
}
def initialize(no_method_error)
super
@location = no_method_error.backtrace_locations.first
@ivar_names = no_method_error.frame_binding.receiver.instance_variables
end
def candidates
super.merge(receiver_name.to_s => @ivar_names)
end
private
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
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
end
SPELL_CHECKERS['NoMethodError'].prepend(IvarNameCorrectable)
end
end
|