類別 DidYouMean::MethodNameChecker

常數

NAMES_TO_EXCLUDE
RB_RESERVED_WORDS

MethodNameChecker::RB_RESERVED_WORDS 是 Ruby 中需要引數的保留字清單。與 VariableNameChecker::RB_RESERVED_WORDS 不同,這些保留字需要引數,並且會因為引數的存在而引發 NoMethodError

如果引發 NoMethodError 並找到最接近的相符項,MethodNameChecker 會使用此清單建議反向字詞。

另請參閱 VariableNameChecker::RB_RESERVED_WORDS

屬性

method_name[R]
receiver[R]

公開類別方法

new(exception) 按一下以切換來源
# File lib/did_you_mean/spell_checkers/method_name_checker.rb, line 42
def initialize(exception)
  @method_name  = exception.name
  @receiver     = exception.receiver
  @private_call = exception.respond_to?(:private_call?) ? exception.private_call? : false
end

公開實例方法

corrections() 按一下以切換來源
# File lib/did_you_mean/spell_checkers/method_name_checker.rb, line 48
def corrections
  @corrections ||= begin
                     dictionary = method_names
                     dictionary = RB_RESERVED_WORDS + dictionary if @private_call

                     SpellChecker.new(dictionary: dictionary).correct(method_name) - names_to_exclude
                   end
end
method_names() 按一下以切換來源
# File lib/did_you_mean/spell_checkers/method_name_checker.rb, line 57
def method_names
  if Object === receiver
    method_names = receiver.methods + receiver.singleton_methods
    method_names += receiver.private_methods if @private_call
    method_names.uniq!
    # Assume that people trying to use a writer are not interested in a reader
    # and vice versa
    if method_name.match?(/=\Z/)
      method_names.select! { |name| name.match?(/=\Z/) }
    else
      method_names.reject! { |name| name.match?(/=\Z/) }
    end
    method_names
  else
    []
  end
end
names_to_exclude() 按一下以切換來源
# File lib/did_you_mean/spell_checkers/method_name_checker.rb, line 75
def names_to_exclude
  Object === receiver ? NAMES_TO_EXCLUDE[receiver.class] : []
end