Skip to content

Commit 674e2ca

Browse files
committed
[ruby/pp] Reduce substring creations
ruby/pp@fee2d39099
1 parent 1dd11fe commit 674e2ca

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

lib/pp.rb

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -313,12 +313,10 @@ def pp_hash(obj)
313313
# A pretty print for a pair of Hash
314314
def pp_hash_pair(k, v)
315315
if Symbol === k
316-
sym_s = k.inspect
317-
if sym_s[1].match?(/["$@!]/) || sym_s[-1].match?(/[%&*+\-\/<=>@\]^`|~]/)
318-
text "#{k.to_s.inspect}:"
319-
else
320-
text "#{k}:"
316+
if k.inspect.match?(%r[\A:["$@!]|[%&*+\-\/<=>@\]^`|~]\z])
317+
k = k.to_s.inspect
321318
end
319+
text "#{k}:"
322320
else
323321
pp k
324322
text ' '

0 commit comments

Comments
 (0)