类 DidYouMean::VariableNameChecker

常量

NAMES_TO_EXCLUDE
RB_RESERVED_WORDS

VariableNameChecker::RB_RESERVED_WORDS 是 Ruby 中所有保留字的列表。它们可以像方法一样声明,并且由于声明方式,错字会导致 Ruby 引发 NameError

如果引发 NameError 并且找到最接近的匹配项,:VariableNameChecker 将使用此列表建议使用反向词,排除

* +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