Issue #16985 has been updated by shyouhei (Shyouhei Urabe).


There are lots of debatable points on String#inspect (for instance its retu=
rn value depends on runtime locale, why?).  Improving it can quite easily j=
ump into a bikeshed.  You might want to separate Hash's and String's discus=
sions and focus on the Hash side, because almost nobody would against that =
part I guess.

----------------------------------------
Feature #16985: Improve `pp` for `Hash` and `String`
https://bugs.ruby-lang.org/issues/16985#change-86320

* Author: marcandre (Marc-Andre Lafortune)
* Status: Open
* Priority: Normal
* Assignee: akr (Akira Tanaka)
----------------------------------------
Could we improve `pp` for `Hash` and `String`:

```ruby
pp({hello: 'My name is "Marc-Andr=E9"'})
# =3D>
{hello: 'My name is "Marc-Andr=E9"'} =

# instead of
{:hello=3D>"My name is \"Marc-Andr=E9\""}
```

If any key is non-symbol, they would continue to be output as `<key> =3D> <=
value>`. If a string contains single quotes, or characters that need escapi=
ng (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?)



-- =

https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=3Dunsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>