ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:109858] [Ruby master Feature#19002] Explicit splat for enumerator kwarg blocks
@ 2022-09-09  1:12 inopinatus (Joshua GOODALL)
  2022-09-09  1:47 ` [ruby-core:109859] " inopinatus (Joshua GOODALL)
  0 siblings, 1 reply; 2+ messages in thread
From: inopinatus (Joshua GOODALL) @ 2022-09-09  1:12 UTC (permalink / raw)
  To: ruby-core

Issue #19002 has been reported by inopinatus (Joshua GOODALL).

----------------------------------------
Feature #19002: Explicit splat for enumerator kwarg blocks
https://bugs.ruby-lang.org/issues/19002

* Author: inopinatus (Joshua GOODALL)
* Status: Open
* Priority: Normal
----------------------------------------
I'm renovating some 2.x-era code that relied heavily on autosplat for block kwargs. As we all know, this throws an ArgumentError in Ruby 3:

``` ruby
ary = [
  { foo: 42, bar: 101 },
  { foo: 99, bar: 123 }
]

ary.map { |foo:, bar:| foo+bar } #=> ArgumentError
```

The nicest solution I could find so far is

``` ruby
module Enumerable
  def splat
    each { |arg| yield **arg }
  end
end
``` ruby

and then

`ary.map.splat { |foo:, bar:| foo+bar } #=> [143, 222]`

and I present this as a feature suggestion.




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

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

* [ruby-core:109859] [Ruby master Feature#19002] Explicit splat for enumerator kwarg blocks
  2022-09-09  1:12 [ruby-core:109858] [Ruby master Feature#19002] Explicit splat for enumerator kwarg blocks inopinatus (Joshua GOODALL)
@ 2022-09-09  1:47 ` inopinatus (Joshua GOODALL)
  0 siblings, 0 replies; 2+ messages in thread
From: inopinatus (Joshua GOODALL) @ 2022-09-09  1:47 UTC (permalink / raw)
  To: ruby-core

Issue #19002 has been updated by inopinatus (Joshua GOODALL).


I also had

``` ruby
module Enumerable
  def **(proc) = each { |arg| proc[**arg] }
end

ary.map ** ->(foo:, bar:) { foo+bar } #=> [143, 222]
```

which is kinda fun, but not so readable.


----------------------------------------
Feature #19002: Explicit splat for enumerator kwarg blocks
https://bugs.ruby-lang.org/issues/19002#change-99097

* Author: inopinatus (Joshua GOODALL)
* Status: Open
* Priority: Normal
----------------------------------------
I'm renovating some 2.x-era code that relied heavily on autosplat for block kwargs. As we all know, this throws an ArgumentError in Ruby 3:

``` ruby
ary = [
  { foo: 42, bar: 101 },
  { foo: 99, bar: 123 }
]

ary.map { |foo:, bar:| foo+bar } #=> ArgumentError
```

The nicest solution I could find so far is

``` ruby
module Enumerable
  def splat
    each { |arg| yield **arg }
  end
end
```

and then

``` ruby
ary.map.splat { |foo:, bar:| foo+bar } #=> [143, 222]
```

and I present this as a feature suggestion.




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

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

end of thread, other threads:[~2022-09-09  1:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-09-09  1:12 [ruby-core:109858] [Ruby master Feature#19002] Explicit splat for enumerator kwarg blocks inopinatus (Joshua GOODALL)
2022-09-09  1:47 ` [ruby-core:109859] " inopinatus (Joshua GOODALL)

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).