class 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 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 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