123456789_123456789_123456789_123456789_123456789_

Class: DidYouMean::MethodNameChecker

Relationships & Source Files
Inherits: Object
Defined in: lib/did_you_mean/spell_checkers/method_name_checker.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(exception) ⇒ MethodNameChecker

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 39

def initialize(exception)
  @method_name  = exception.name
  @receiver     = exception.receiver
  @private_call = exception.respond_to?(:private_call?) ? exception.private_call? : false
end

Instance Attribute Details

#method_name (readonly)

[ GitHub ]

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

attr_reader :method_name, :receiver

#receiver (readonly)

[ GitHub ]

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

attr_reader :method_name, :receiver

Instance Method Details

#corrections

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 45

def corrections
  @corrections ||= begin
                     dictionary = method_names
                     dictionary = RB_RESERVED_WORDS + dictionary if @private_call

                     SpellChecker.new(dictionary: dictionary).correct(method_name) - names_to_exclude
                   end
end

#method_names

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 54

def method_names
  if Object === receiver
    method_names = receiver.methods + receiver.singleton_methods
    method_names += receiver.private_methods if @private_call
    method_names.uniq!
    method_names
  else
    []
  end
end

#names_to_exclude

[ GitHub ]

  
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 65

def names_to_exclude
  Object === receiver ? NAMES_TO_EXCLUDE[receiver.class] : []
end