類別 DidYouMean::VariableNameChecker

常數

NAMES_TO_EXCLUDE
RB_RESERVED_WORDS

VariableNameChecker::RB_RESERVED_WORDS 是 Ruby 中所有保留字的清單。它們可以宣告為方法,而拼字錯誤會導致 Ruby 因為宣告方式而引發 NameError

:VariableNameChecker 會使用此清單,在引發 NameError 且找到最接近的比對時,建議使用反轉的字詞,排除

* +do+
* +if+
* +in+
* +or+

另請參閱 MethodNameChecker::RB_RESERVED_WORDS

屬性

cvar_names[R]
ivar_names[R]
lvar_names[R]
method_names[R]
name[R]

公開類別方法

new(exception) 按一下以切換來源
# File lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb, line 68
def initialize(exception)
  @name       = exception.name.to_s.tr("@", "")
  @lvar_names = exception.respond_to?(:local_variables) ? exception.local_variables : []
  receiver    = exception.receiver

  @method_names = receiver.methods + receiver.private_methods
  @ivar_names   = receiver.instance_variables
  @cvar_names   = receiver.class.class_variables
  @cvar_names  += receiver.class_variables if receiver.kind_of?(Module)
end

公開實例方法

corrections() 按一下以切換來源
# File lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb, line 79
def corrections
  @corrections ||= SpellChecker
                 .new(dictionary: (RB_RESERVED_WORDS + lvar_names + method_names + ivar_names + cvar_names))
                 .correct(name).uniq - NAMES_TO_EXCLUDE[@name]
end