From bd11eefd6cc724919dd645965856966744a554c6 Mon Sep 17 00:00:00 2001 From: Yuki Nishijima Date: Tue, 19 Mar 2024 10:25:55 +0900 Subject: [PATCH] Do not use #inspect to avoid unexpected performance degradation closes #100 --- lib/did_you_mean/spell_checkers/key_error_checker.rb | 10 +++++++++- .../spell_checkers/pattern_key_name_checker.rb | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/did_you_mean/spell_checkers/key_error_checker.rb b/lib/did_you_mean/spell_checkers/key_error_checker.rb index be4bea77..955bff1b 100644 --- a/lib/did_you_mean/spell_checkers/key_error_checker.rb +++ b/lib/did_you_mean/spell_checkers/key_error_checker.rb @@ -14,7 +14,15 @@ def corrections private def exact_matches - @exact_matches ||= @keys.select { |word| @key == word.to_s }.map(&:inspect) + @exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) } + end + + def format_object(symbol_or_object) + if symbol_or_object.is_a?(Symbol) + ":#{symbol_or_object}" + else + symbol_or_object.to_s + end end end end diff --git a/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb b/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb index ed263c8f..622d4dee 100644 --- a/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb +++ b/lib/did_you_mean/spell_checkers/pattern_key_name_checker.rb @@ -14,7 +14,15 @@ def corrections private def exact_matches - @exact_matches ||= @keys.select { |word| @key == word.to_s }.map(&:inspect) + @exact_matches ||= @keys.select { |word| @key == word.to_s }.map { |obj| format_object(obj) } + end + + def format_object(symbol_or_object) + if symbol_or_object.is_a?(Symbol) + ":#{symbol_or_object}" + else + symbol_or_object.to_s + end end end end