diff options
author | Matthew Boeh <m@mboeh.com> | 2022-12-05 05:16:27 -0800 |
---|---|---|
committer | git <svn-admin@ruby-lang.org> | 2022-12-05 13:16:33 +0000 |
commit | 1602d75c34c39f6d2f5a505a6532c3664288ef06 (patch) | |
tree | bbb4f742941938167bfb4412d3444182a041c70e /lib | |
parent | 74923aaf31ae49cd372f2fe54baa4115a20bfe76 (diff) | |
download | ruby-1602d75c34c39f6d2f5a505a6532c3664288ef06.tar.gz |
[ruby/did_you_mean] Do not suggest #name= for #name and vice versa
(https://github.com/ruby/did_you_mean/pull/180)
* Do not suggest #name= for #name and vice versa
* Avoid allocating unnecessary MatchData
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
Co-authored-by: Jean byroot Boussier <jean.boussier+github@shopify.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/did_you_mean/spell_checkers/method_name_checker.rb | 7 |
1 files changed, 7 insertions, 0 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 d8ebaa4616..b5cbbb5da6 100644 --- a/lib/did_you_mean/spell_checkers/method_name_checker.rb +++ b/lib/did_you_mean/spell_checkers/method_name_checker.rb @@ -59,6 +59,13 @@ module DidYouMean method_names = receiver.methods + receiver.singleton_methods method_names += receiver.private_methods if @private_call method_names.uniq! + # Assume that people trying to use a writer are not interested in a reader + # and vice versa + if method_name.match?(/=\Z/) + method_names.select! { |name| name.match?(/=\Z/) } + else + method_names.reject! { |name| name.match?(/=\Z/) } + end method_names else [] |