summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2025-10-05 12:59:52 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2025-10-05 19:58:31 +0900
commit674e2ca9452121a3e3066e04ecd51ba8d863cf2b (patch)
tree8cf1aef9a2402169f21e681f4a95576c2bd2c388
parent1dd11fe8c8a238ea88f5abbdb673de313a82ede2 (diff)
[ruby/pp] Reduce substring creations
https://github.com/ruby/pp/commit/fee2d39099
-rw-r--r--lib/pp.rb8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/pp.rb b/lib/pp.rb
index 2c7f41eadd..e790f499d4 100644
--- a/lib/pp.rb
+++ b/lib/pp.rb
@@ -313,12 +313,10 @@ class PP < PrettyPrint
# A pretty print for a pair of Hash
def pp_hash_pair(k, v)
if Symbol === k
- sym_s = k.inspect
- if sym_s[1].match?(/["$@!]/) || sym_s[-1].match?(/[%&*+\-\/<=>@\]^`|~]/)
- text "#{k.to_s.inspect}:"
- else
- text "#{k}:"
+ if k.inspect.match?(%r[\A:["$@!]|[%&*+\-\/<=>@\]^`|~]\z])
+ k = k.to_s.inspect
end
+ text "#{k}:"
else
pp k
text ' '