diff options
author | Yusuke Endoh <mame@ruby-lang.org> | 2021-06-18 17:45:10 +0900 |
---|---|---|
committer | Yusuke Endoh <mame@ruby-lang.org> | 2021-06-29 15:49:51 +0900 |
commit | 809f1203744e25fc4d095863593edbfb71529249 (patch) | |
tree | 3c939e581d3085f092c5320bfd5893c3e06e14db | |
parent | 612b6fcd371adc199fb4503941edfdbbac704ef4 (diff) |
Use String#include? instead of end_with? to avoid message duplication
Previously, did_you_mean used `msg.end_with?(suggestion)` to check if
its suggestion is already added.
I'm now creating a gem that also modifies Exception's message. This
breaks did_you_mean's duplication check.
This change makes the check use String#include? instead of end_with?.
https://github.com/ruby/did_you_mean/commit/b35e030549
-rw-r--r-- | lib/did_you_mean/core_ext/name_error.rb | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/lib/did_you_mean/core_ext/name_error.rb b/lib/did_you_mean/core_ext/name_error.rb index 74febccfe9..7e99282b41 100644 --- a/lib/did_you_mean/core_ext/name_error.rb +++ b/lib/did_you_mean/core_ext/name_error.rb @@ -15,7 +15,7 @@ module DidYouMean msg = super.dup suggestion = DidYouMean.formatter.message_for(corrections) - msg << suggestion if !msg.end_with?(suggestion) + msg << suggestion if !msg.include?(suggestion) msg rescue super |