ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90304] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly
       [not found] <redmine.issue-15381.20181205082504@ruby-lang.org>
@ 2018-12-05  8:25 ` sawadatsuyoshi
  2018-12-05  8:28 ` [ruby-core:90305] " sawadatsuyoshi
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2018-12-05  8:25 UTC (permalink / raw)
  To: ruby-core

Issue #15381 has been reported by sawa (Tsuyoshi Sawada).

----------------------------------------
Feature #15381: Let double splat call `to_hash` implicitly
https://bugs.ruby-lang.org/issues/15381

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The single splat calls `to_a` implicitly on the object (if it is not an array already) so that, for example, we have the convenience of writing conditions in an array literal:

```ruby
a = [
  *(:foo if some_condition),
  *(:bar if another_condition),
]
```

And the ampersand implicitly calls `to_proc` on the object (if it is not a proc already) so that we can substitute a block with an ampersand followed by a symbol:

```ruby
some_method(&:some_method_name)
```

Unlike the single splat and ampersand, the double splat does not seem to implicitly call a corresponding method. I propose that the double splat should call `to_hash` implicitly on the object if it not already a hash so that we can, for example, write a condition in a hash literal as follows:

```ruby
h = {
  **({a: 1} if some_condition),
  **({b: 2) if another_condition),
}
```

There may be some other benefits of this feature that I have not noticed yet.



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:90305] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly
       [not found] <redmine.issue-15381.20181205082504@ruby-lang.org>
  2018-12-05  8:25 ` [ruby-core:90304] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly sawadatsuyoshi
@ 2018-12-05  8:28 ` sawadatsuyoshi
  2018-12-05 12:58 ` [ruby-core:90310] " shevegen
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 5+ messages in thread
From: sawadatsuyoshi @ 2018-12-05  8:28 UTC (permalink / raw)
  To: ruby-core

Issue #15381 has been updated by sawa (Tsuyoshi Sawada).


In case my intention was not clear, in the example I gave for the double splat, I expected `**nil` to be evaluated as `{}`.

----------------------------------------
Feature #15381: Let double splat call `to_hash` implicitly
https://bugs.ruby-lang.org/issues/15381#change-75411

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The single splat calls `to_a` implicitly on the object (if it is not an array already) so that, for example, we have the convenience of writing conditions in an array literal:

```ruby
a = [
  *(:foo if some_condition),
  *(:bar if another_condition),
]
```

And the ampersand implicitly calls `to_proc` on the object (if it is not a proc already) so that we can substitute a block with an ampersand followed by a symbol:

```ruby
some_method(&:some_method_name)
```

Unlike the single splat and ampersand, the double splat does not seem to implicitly call a corresponding method. I propose that the double splat should call `to_hash` implicitly on the object if it not already a hash so that we can, for example, write a condition in a hash literal as follows:

```ruby
h = {
  **({a: 1} if some_condition),
  **({b: 2) if another_condition),
}
```

There may be some other benefits of this feature that I have not noticed yet.



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:90310] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly
       [not found] <redmine.issue-15381.20181205082504@ruby-lang.org>
  2018-12-05  8:25 ` [ruby-core:90304] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly sawadatsuyoshi
  2018-12-05  8:28 ` [ruby-core:90305] " sawadatsuyoshi
@ 2018-12-05 12:58 ` shevegen
  2019-09-20  2:10 ` [ruby-core:94995] [Ruby master " drenmi
  2019-09-21 21:05 ` [ruby-core:95024] " eregontp
  4 siblings, 0 replies; 5+ messages in thread
From: shevegen @ 2018-12-05 12:58 UTC (permalink / raw)
  To: ruby-core

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


I myself have used *foobar quite a lot in ruby code, such as in:

    def foobar(*args)
      args.each # and do something then
    end

and I have also used &: considerably often too. The most frequent
use case for me personally is to use &: together with .map(). This
is an area where I actually prefer e. g. .map(&:strip) as opposed
to something like .map {|line| line.strip } or something like 
that. While I consider the second variant more readable to me,
the &: variant is significantly shorter. (& is not very pretty
though so I try to not use it too often).

I have not yet used **, I think (strangely enough; perhaps I have not
needed it so far). So I can not say much about the proposal itself
either way. I am both clueless and neither pro nor con. :)

I agree with the above reasoning of nil.to_h which makes sense (if
the functionality in itself is approved and I guess we have to ask
matz about this).

I think this is where matz has to decide whether ** should behave as
described, stay as it is (status quo), or have some other (implicit?)
meaning that was not yet mentioned. I really can not say either way,
but I think what is also said in the issue here is that * has a better
defined meaning right now than does **. So this is where I think matz
has to decide either way.

I would recommend adding this suggestion to an upcoming developer meeting,
but perhaps not for 2018 but 2019 instead - last dev meeting this year
should ideally be for the ruby x-mas release. :D

On a side note, does anyone have one or more good or simple use cases 
for **? I am trying to find an example for where it may be used but
I do not have any local example.

Last but not least, although I understand that the example given was
mostly to illustrate a point, so that's fine; the * and ** variants
with () and conditionals, are a bit ugly. :P

I understand it is the illustration of an example but I really hope
people don't write code such as "**({a: 1} if some_condition)"; it
takes my brain quite some time to process.

----------------------------------------
Feature #15381: Let double splat call `to_hash` implicitly
https://bugs.ruby-lang.org/issues/15381#change-75414

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The single splat calls `to_a` implicitly on the object (if it is not an array already) so that, for example, we have the convenience of writing conditions in an array literal:

```ruby
a = [
  *(:foo if some_condition),
  *(:bar if another_condition),
]
```

And the ampersand implicitly calls `to_proc` on the object (if it is not a proc already) so that we can substitute a block with an ampersand followed by a symbol:

```ruby
some_method(&:some_method_name)
```

Unlike the single splat and ampersand, the double splat does not seem to implicitly call a corresponding method. I propose that the double splat should call `to_hash` implicitly on the object if it not already a hash so that we can, for example, write a condition in a hash literal as follows:

```ruby
h = {
  **({a: 1} if some_condition),
  **({b: 2) if another_condition),
}
```

There may be some other benefits of this feature that I have not noticed yet.



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:94995] [Ruby master Feature#15381] Let double splat call `to_hash` implicitly
       [not found] <redmine.issue-15381.20181205082504@ruby-lang.org>
                   ` (2 preceding siblings ...)
  2018-12-05 12:58 ` [ruby-core:90310] " shevegen
@ 2019-09-20  2:10 ` drenmi
  2019-09-21 21:05 ` [ruby-core:95024] " eregontp
  4 siblings, 0 replies; 5+ messages in thread
From: drenmi @ 2019-09-20  2:10 UTC (permalink / raw)
  To: ruby-core

Issue #15381 has been updated by ted (Ted Johansson).


I came here to file this feature request, only to find this had already been proposed. This would be beautiful, indeed. :-)

----------------------------------------
Feature #15381: Let double splat call `to_hash` implicitly
https://bugs.ruby-lang.org/issues/15381#change-81623

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The single splat calls `to_a` implicitly on the object (if it is not an array already) so that, for example, we have the convenience of writing conditions in an array literal:

```ruby
a = [
  *(:foo if some_condition),
  *(:bar if another_condition),
]
```

And the ampersand implicitly calls `to_proc` on the object (if it is not a proc already) so that we can substitute a block with an ampersand followed by a symbol:

```ruby
some_method(&:some_method_name)
```

Unlike the single splat and ampersand, the double splat does not seem to implicitly call a corresponding method. I propose that the double splat should call `to_hash` implicitly on the object if it not already a hash so that we can, for example, write a condition in a hash literal as follows:

```ruby
h = {
  **({a: 1} if some_condition),
  **({b: 2) if another_condition),
}
```

There may be some other benefits of this feature that I have not noticed yet.



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [ruby-core:95024] [Ruby master Feature#15381] Let double splat call `to_hash` implicitly
       [not found] <redmine.issue-15381.20181205082504@ruby-lang.org>
                   ` (3 preceding siblings ...)
  2019-09-20  2:10 ` [ruby-core:94995] [Ruby master " drenmi
@ 2019-09-21 21:05 ` eregontp
  4 siblings, 0 replies; 5+ messages in thread
From: eregontp @ 2019-09-21 21:05 UTC (permalink / raw)
  To: ruby-core

Issue #15381 has been updated by Eregon (Benoit Daloze).


`nil` does not respond to `to_hash` though, how do you propose to deal with that?

Should `**` call `to_h` rather than `to_hash`, similar to `*` calling `to_a` and not `to_ary`?

Your comment https://bugs.ruby-lang.org/issues/15381#note-1 shows that, but I read the mailing list and that doesn't include the edit.

----------------------------------------
Feature #15381: Let double splat call `to_hash` implicitly
https://bugs.ruby-lang.org/issues/15381#change-81651

* Author: sawa (Tsuyoshi Sawada)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
----------------------------------------
The single splat calls `to_a` implicitly on the object (if it is not an array already) so that, for example, we have the convenience of writing conditions in an array literal:

```ruby
a = [
  *(:foo if some_condition),
  *(:bar if another_condition),
]
```

And the ampersand implicitly calls `to_proc` on the object (if it is not a proc already) so that we can substitute a block with an ampersand followed by a symbol:

```ruby
some_method(&:some_method_name)
```

Unlike the single splat and ampersand, the double splat does not seem to implicitly call a corresponding method. I propose that the double splat should call `to_hash` implicitly on the object if it not already a hash so that we can, for example, write a condition in a hash literal as follows:

```ruby
h = {
  **({a: 1} if some_condition),
  **({b: 2) if another_condition),
}
```

There may be some other benefits of this feature that I have not noticed yet.



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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2019-09-21 21:06 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15381.20181205082504@ruby-lang.org>
2018-12-05  8:25 ` [ruby-core:90304] [Ruby trunk Feature#15381] Let double splat call `to_hash` implicitly sawadatsuyoshi
2018-12-05  8:28 ` [ruby-core:90305] " sawadatsuyoshi
2018-12-05 12:58 ` [ruby-core:90310] " shevegen
2019-09-20  2:10 ` [ruby-core:94995] [Ruby master " drenmi
2019-09-21 21:05 ` [ruby-core:95024] " eregontp

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).