Class: DidYouMean::VariableNameChecker
- Inherits:
-
Object
- Object
- DidYouMean::VariableNameChecker
- Defined in:
- lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
Constant Summary collapse
- NAMES_TO_EXCLUDE =
{ 'foo' => [:fork] }
- RB_PREDEFINED_OBJECTS =
[:false, :true, :nil]
Instance Attribute Summary collapse
-
#cvar_names ⇒ Object
readonly
Returns the value of attribute cvar_names.
-
#ivar_names ⇒ Object
readonly
Returns the value of attribute ivar_names.
-
#lvar_names ⇒ Object
readonly
Returns the value of attribute lvar_names.
-
#method_names ⇒ Object
readonly
Returns the value of attribute method_names.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #corrections ⇒ Object
-
#initialize(exception) ⇒ VariableNameChecker
constructor
A new instance of VariableNameChecker.
Constructor Details
#initialize(exception) ⇒ VariableNameChecker
Returns a new instance of VariableNameChecker.
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 13 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 |
Instance Attribute Details
#cvar_names ⇒ Object (readonly)
Returns the value of attribute cvar_names.
7 8 9 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 7 def cvar_names @cvar_names end |
#ivar_names ⇒ Object (readonly)
Returns the value of attribute ivar_names.
7 8 9 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 7 def ivar_names @ivar_names end |
#lvar_names ⇒ Object (readonly)
Returns the value of attribute lvar_names.
7 8 9 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 7 def lvar_names @lvar_names end |
#method_names ⇒ Object (readonly)
Returns the value of attribute method_names.
7 8 9 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 7 def method_names @method_names end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
7 8 9 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 7 def name @name end |
Instance Method Details
#corrections ⇒ Object
24 25 26 27 28 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 24 def corrections @corrections ||= SpellChecker .new(dictionary: (RB_PREDEFINED_OBJECTS + lvar_names + method_names + ivar_names + cvar_names)) .correct(name) - NAMES_TO_EXCLUDE[@name] end |