Project

General

Profile

Actions

Feature #16985

open

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

Added by marcandre (Marc-Andre Lafortune) over 4 years ago. Updated 8 months ago.

Status:
Assigned
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?)

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like0Like0Like0