Sha256: ee1c959717ae6ca4e9d80b9861fbe6dd10d061519d1851c9a01ea0be2c67f7f2
Contents?: true
Size: 1.49 KB
Versions: 1
Compression:
Stored size: 1.49 KB
Contents
require "did_you_mean/spell_checker" module DidYouMean class MethodNameChecker attr_reader :method_name, :receiver NAMES_TO_EXCLUDE = { NilClass => nil.methods } NAMES_TO_EXCLUDE.default = [] # +MethodNameChecker::RB_RESERVED_WORDS+ is the list of reserved words in # Ruby that take an argument. Unlike # +VariableNameChecker::RB_RESERVED_WORDS+, these reserved words require # an argument, and a +NoMethodError+ is raised due to the presence of the # argument. # # The +MethodNameChecker+ will use this list to suggest a reversed word if # a +NoMethodError+ is raised and found closest matches. # # Also see +VariableNameChecker::RB_RESERVED_WORDS+. RB_RESERVED_WORDS = %i( alias case def defined? elsif end ensure for rescue super undef unless until when while yield ) def initialize(exception) @method_name = exception.name @receiver = exception.receiver @private_call = exception.respond_to?(:private_call?) ? exception.private_call? : false end def corrections @corrections ||= SpellChecker.new(dictionary: RB_RESERVED_WORDS + method_names).correct(method_name) - NAMES_TO_EXCLUDE[@receiver.class] end def method_names method_names = receiver.methods + receiver.singleton_methods method_names += receiver.private_methods if @private_call method_names.uniq! method_names end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
did_you_mean-1.3.1 | lib/did_you_mean/spell_checkers/method_name_checker.rb |