summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYuki Nishijima <yk.nishijima@gmail.com>2019-12-04 19:55:01 -0500
committerYuki Nishijima <yk.nishijima@gmail.com>2019-12-04 19:55:01 -0500
commit18d3b5a93a2d52412f8f563d58db682b41d5c98c (patch)
tree79e394046658977639b6912058e8e5566fbb677f
parent88ee375dd6c93523bd5d8f9517e49215b9d8cf67 (diff)
Do not attempt to call methods on the receiver if it is a basic object
-rw-r--r--lib/did_you_mean/spell_checkers/method_name_checker.rb18
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