Class: DidYouMean::MethodNameChecker
- Inherits:
-
Object
- Object
- DidYouMean::MethodNameChecker
- Defined in:
- lib/did_you_mean/spell_checkers/method_name_checker.rb
Constant Summary collapse
- NAMES_TO_EXCLUDE =
{ NilClass => nil.methods }
- RB_RESERVED_WORDS =
MethodNameChecker::RB_RESERVED_WORDS
is the list of reserved words in Ruby that take an argument. UnlikeVariableNameChecker::RB_RESERVED_WORDS
, these reserved words require an argument, and aNoMethodError
is raised due to the presence of the argument.The
MethodNameChecker
will use this list to suggest a reversed word if aNoMethodError
is raised and found closest matches.Also see
VariableNameChecker::RB_RESERVED_WORDS
. %i( alias case def defined? elsif end ensure for rescue super undef unless until when while yield )
Instance Attribute Summary collapse
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#receiver ⇒ Object
readonly
Returns the value of attribute receiver.
Instance Method Summary collapse
- #corrections ⇒ Object
-
#initialize(exception) ⇒ MethodNameChecker
constructor
A new instance of MethodNameChecker.
- #method_names ⇒ Object
- #names_to_exclude ⇒ Object
Constructor Details
#initialize(exception) ⇒ MethodNameChecker
Returns a new instance of MethodNameChecker.
39 40 41 42 43 |
# 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 ⇒ Object (readonly)
Returns the value of attribute method_name.
5 6 7 |
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 5 def method_name @method_name end |
#receiver ⇒ Object (readonly)
Returns the value of attribute receiver.
5 6 7 |
# File 'lib/did_you_mean/spell_checkers/method_name_checker.rb', line 5 def receiver @receiver end |
Instance Method Details
#corrections ⇒ Object
45 46 47 48 49 50 51 52 |
# 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 ⇒ Object
54 55 56 57 58 59 60 61 62 63 |
# 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 ⇒ Object
65 66 67 |
# 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 |