[前][次][番号順一覧][スレッド一覧]

ruby-changes:66625

From: Yusuke <ko1@a...>
Date: Tue, 29 Jun 2021 17:28:07 +0900 (JST)
Subject: [ruby-changes:66625] 809f120374 (master): Use String#include? instead of end_with? to avoid message duplication

https://git.ruby-lang.org/ruby.git/commit/?id=809f120374

From 809f1203744e25fc4d095863593edbfb71529249 Mon Sep 17 00:00:00 2001
From: Yusuke Endoh <mame@r...>
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 74febcc..7e99282 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 https://github.com/ruby/ruby/blob/trunk/lib/did_you_mean/core_ext/name_error.rb#L15
       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.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]