From ec7e082906d5c32c5e895137fd0d562fa237ca12 Mon Sep 17 00:00:00 2001 From: Mau Magnaguagno Date: Tue, 27 Dec 2022 14:05:28 -0300 Subject: [PATCH] [ruby/irb] Refactor RubyLex#process_literal_type (https://github.com/ruby/irb/pull/350) Simplify part of regex ``[_a-zA-Z0-9]`` with equivalent shorthand ``\w``. Replace case-when with match ``$1`` or default value ``?"``, making intention more clear. --- lib/irb/ruby-lex.rb | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/lib/irb/ruby-lex.rb b/lib/irb/ruby-lex.rb index 030cf79ee1..04d9bceb07 100644 --- a/lib/irb/ruby-lex.rb +++ b/lib/irb/ruby-lex.rb @@ -782,13 +782,8 @@ class RubyLex when :on_qsymbols_beg then ?] when :on_symbols_beg then ?] when :on_heredoc_beg - start_token&.tok =~ /<<[-~]?(['"`])[_a-zA-Z0-9]+\1/ - case $1 - when ?" then ?" - when ?' then ?' - when ?` then ?` - else ?" - end + start_token&.tok =~ /<<[-~]?(['"`])\w+\1/ + $1 || ?" else nil end