Class: DidYouMean::MethodNameChecker

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SpellCheckable

#corrections

Constructor Details

#initialize(exception) ⇒ MethodNameChecker

Returns a new instance of MethodNameChecker.



6
7
8
9
10
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 6

def initialize(exception)
  @method_name = exception.name
  @receiver    = exception.receiver
  @has_args    = !exception.args&.empty?
end

Instance Attribute Details

#method_nameObject (readonly)

Returns the value of attribute method_name.



4
5
6
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 4

def method_name
  @method_name
end

#receiverObject (readonly)

Returns the value of attribute receiver.



4
5
6
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 4

def receiver
  @receiver
end

Instance Method Details

#candidatesObject



12
13
14
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 12

def candidates
  { method_name => method_names }
end

#method_namesObject



16
17
18
19
20
21
22
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 16

def method_names
  method_names = receiver.methods + receiver.singleton_methods
  method_names += receiver.private_methods if @has_args
  method_names.delete(method_name)
  method_names.uniq!
  method_names
end