Issue #16985 has been updated by shevegen (Robert A. Heiler).


I don't have any big preference, but I tend to agree with sawa too.

When I first read the proposal, I was confused in that two suggestions seem=
 to be combined - or at the least I was reading it that way.

(1) Display "foo: bar" rather than ":foo =3D> bar".

and

(2) Using:

   'My name is "abc"'

Rather than:

    "My name is \"Marc-Andr=E9\""

Sorry if I misunderstood it initially. I believe that both situations are f=
ine BUT!
I'll soon add what I think may be a problem.

First, let me say that I somewhat agree with vo.x in the sense that the has=
h rocket
is the "default" syntax for hash, and the foo: :bar is a "shortcut". Note t=
hat I use
the foo: :bar notation a lot myself, but ruby even sort of shows you that i=
t is
an alias to the hashrocket rather than the reverse - in IRB:

    hash =3D { foo: :bar, cat: :tom }
    hash # =3D> {:foo=3D>:bar, :cat=3D>:tom}

So there we have the =3D> notation. And I think this should stay the defaul=
t too, =

similar to what vo.x wrote.

At the same time, though, I think a part of marcandre's suggestion was to h=
ave =

pp be more flexible in use. So if a ruby user prefers what marcandre sugges=
ted,
then I am fine with this. I believe that this should not become the default,
though. The current default should remain, but if people are able to custom=
ize
it to their likings, then I am all for it.

How to customize this? Well. Perhaps PP could have a toplevel configuration =

style or something; and an option hash for pp() itself. (Toplevel configura=
tion
could then be used to set up PP once.)

I should also say that I know the ap (awesome_print), and it has colour sup=
port,
but I realized that the colours confused me more than it helped me, so I we=
nt
back to pp. I use pp a LOT. I don't have a really strong opinion per se, but
I think it would be better to default to how things are right now, but allow
people to customize the behaviour of pp (perhaps even at compile time if th=
ey
feel strongly about it).

benoit wrote:

> I think symbol_key: value would be nice in Hash#inspect, even if there are
> also non-Symbol keys.

Well, if people can decide this on their own, then that is fine - but I per=
sonally
would rather retain the current behaviour here, for my own projects.

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

* 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>