Project

General

Profile

Feature #16985

Improve `pp` for `Hash` and `String`

Added by marcandre (Marc-Andre Lafortune) 3 months ago. Updated 3 months ago.

Status:
Open
Priority:
Normal
Target version:
-
[ruby-core:98938]

Description

Could we improve pp for Hash and String:

pp({hello: 'My name is "Marc-André"'})
# =>
{hello: 'My name is "Marc-André"'} 
# instead of
{:hello=>"My name is \"Marc-André\""}

If any key is non-symbol, they would continue to be output as <key> => <value>. If a string contains single quotes, or characters that need escaping (e.g. "\n"), current format would be used.

I'll gladly provide a PR if this is deemed acceptable.

I would even like this for String#inspect and Hash#inspect but it's not clear if this could lead to much incompatibility (maybe test suites?)

Also available in: Atom PDF