[#98645] [Ruby master Misc#16933] DevelopersMeeting20200618Japan — mame@...

Issue #16933 has been reported by mame (Yusuke Endoh).

14 messages 2020/06/04

[#98663] [Ruby master Bug#16936] `make check TESTS="-n !/Foo#method/"` not skipping the test case — jaruga@...

Issue #16936 has been reported by jaruga (Jun Aruga).

13 messages 2020/06/05

[#98772] [Ruby master Bug#16959] Weakmap has specs and third-party usage despite being a private API — headius@...

Issue #16959 has been reported by headius (Charles Nutter).

13 messages 2020/06/12

[#98826] [Ruby master Feature#16963] Remove English.rb from Ruby 2.8/3.0 — hsbt@...

Issue #16963 has been reported by hsbt (Hiroshi SHIBATA).

9 messages 2020/06/16

[#98920] [Ruby master Bug#16978] Ruby should not use realpath for __FILE__ — v.ondruch@...

Issue #16978 has been reported by vo.x (Vit Ondruch).

24 messages 2020/06/23

[#98947] [Ruby master Feature#16986] Anonymous Struct literal — ko1@...

Issue #16986 has been reported by ko1 (Koichi Sasada).

66 messages 2020/06/26

[#98964] [Ruby master Feature#16989] Sets: need ♥️ — marcandre-ruby-core@...

Issue #16989 has been reported by marcandre (Marc-Andre Lafortune).

33 messages 2020/06/26

[#98965] [Ruby master Feature#16990] Sets: operators compatibility with Array — marcandre-ruby-core@...

Issue #16990 has been reported by marcandre (Marc-Andre Lafortune).

11 messages 2020/06/26

[#98968] [Ruby master Feature#16993] Sets: from hash keys using Hash#key_set — marcandre-ruby-core@...

Issue #16993 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/06/26

[#98997] [Ruby master Feature#17000] 2.7.2 turns off deprecation warnings by deafult — mame@...

Issue #17000 has been reported by mame (Yusuke Endoh).

16 messages 2020/06/30

[ruby-core:98950] [Ruby master Feature#16985] Improve `pp` for `Hash` and `String`

From: shevegen@...
Date: 2020-06-26 09:51:53 UTC
List: ruby-core #98950
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 => bar".

and

(2) Using:

   'My name is "abc"'

Rather than:

    "My name is \"Marc-Andr饅""

Sorry if I misunderstood it initially. I believe that both situations are fine 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 hash rocket
is the "default" syntax for hash, and the foo: :bar is a "shortcut". Note that I use
the foo: :bar notation a lot myself, but ruby even sort of shows you that it is
an alias to the hashrocket rather than the reverse - in IRB:

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

So there we have the => notation. And I think this should stay the default too, 
similar to what vo.x wrote.

At the same time, though, I think a part of marcandre's suggestion was to have 
pp be more flexible in use. So if a ruby user prefers what marcandre suggested,
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 customize
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 configuration
could then be used to set up PP once.)

I should also say that I know the ap (awesome_print), and it has colour support,
but I realized that the colours confused me more than it helped me, so I went
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 they
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 personally
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'})
# =>
{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?)



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

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

In This Thread

Prev Next