[ruby-core:109858] [Ruby master Feature#19002] Explicit splat for enumerator kwarg blocks
From:
"inopinatus (Joshua GOODALL)" <noreply@...>
Date:
2022-09-09 01:12:36 UTC
List:
ruby-core #109858
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/
Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>