Class: DidYouMean::VariableNameChecker

Inherits:
Object
  • Object
show all
Includes:
SpellCheckable
Defined in:
lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SpellCheckable

#corrections

Constructor Details

#initialize(exception) ⇒ VariableNameChecker

Returns a new instance of VariableNameChecker.



8
9
10
11
12
13
14
15
16
17
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 8

def initialize(exception)
  @name       = exception.name.to_s.tr("@", "")
  @lvar_names = 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_namesObject (readonly)

Returns the value of attribute cvar_names.



6
7
8
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 6

def cvar_names
  @cvar_names
end

#ivar_namesObject (readonly)

Returns the value of attribute ivar_names.



6
7
8
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 6

def ivar_names
  @ivar_names
end

#lvar_namesObject (readonly)

Returns the value of attribute lvar_names.



6
7
8
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 6

def lvar_names
  @lvar_names
end

#method_namesObject (readonly)

Returns the value of attribute method_names.



6
7
8
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 6

def method_names
  @method_names
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 6

def name
  @name
end

Instance Method Details

#candidatesObject



19
20
21
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb', line 19

def candidates
  { name => (lvar_names + method_names + ivar_names + cvar_names) }
end