diff options
author | Yuki Nishijima <[email protected]> | 2019-12-04 19:55:01 -0500 |
---|---|---|
committer | Yuki Nishijima <[email protected]> | 2019-12-04 19:55:01 -0500 |
commit | 18d3b5a93a2d52412f8f563d58db682b41d5c98c (patch) | |
tree | 79e394046658977639b6912058e8e5566fbb677f /lib/did_you_mean/spell_checkers | |
parent | 88ee375dd6c93523bd5d8f9517e49215b9d8cf67 (diff) |
Do not attempt to call methods on the receiver if it is a basic object
Diffstat (limited to 'lib/did_you_mean/spell_checkers')
-rw-r--r-- | lib/did_you_mean/spell_checkers/method_name_checker.rb | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/did_you_mean/spell_checkers/method_name_checker.rb b/lib/did_you_mean/spell_checkers/method_name_checker.rb index 3ca8a37e08..3a38245f0c 100644 --- a/lib/did_you_mean/spell_checkers/method_name_checker.rb +++ b/lib/did_you_mean/spell_checkers/method_name_checker.rb @@ -43,14 +43,22 @@ module DidYouMean end def corrections - @corrections ||= SpellChecker.new(dictionary: RB_RESERVED_WORDS + method_names).correct(method_name) - NAMES_TO_EXCLUDE[@receiver.class] + @corrections ||= SpellChecker.new(dictionary: RB_RESERVED_WORDS + method_names).correct(method_name) - names_to_exclude end def method_names - method_names = receiver.methods + receiver.singleton_methods - method_names += receiver.private_methods if @private_call - method_names.uniq! - 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 + + def names_to_exclude + Object === receiver ? NAMES_TO_EXCLUDE[receiver.class] : [] end end end |