Sha256: 95082b24deacc4da0954a9741e26b8cefb1cd4a26fcd3ac075c8d0b5a2b1d0bf
Contents?: true
Size: 1.3 KB
Versions: 1
Compression:
Stored size: 1.3 KB
Contents
module DidYouMean class MethodNameChecker include SpellCheckable attr_reader :method_name, :receiver REPLS = { "(irb)" => -> { Readline::HISTORY.to_a.last } } def initialize(exception) @method_name = exception.name @receiver = exception.receiver @binding = exception.frame_binding @location = exception.backtrace_locations.first @ivar_names = VariableNameChecker.new(exception).ivar_names end def candidates { method_name => method_names, receiver_name.to_s => @ivar_names } end def method_names method_names = receiver.methods + receiver.singleton_methods method_names += receiver.private_methods if receiver.equal?(@binding.receiver) method_names.delete(method_name) method_names.uniq! method_names end 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 private 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 end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
did_you_mean-1.0.0.beta2 | lib/did_you_mean/spell_checkers/method_name_checker.rb |