From 809f1203744e25fc4d095863593edbfb71529249 Mon Sep 17 00:00:00 2001 From: Yusuke Endoh Date: Fri, 18 Jun 2021 17:45:10 +0900 Subject: 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 --- lib/did_you_mean/core_ext/name_error.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 -- cgit v1.2.3