From: "inopinatus (Joshua GOODALL)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:109859] [Ruby master Feature#19002] Explicit splat for enumerator kwarg blocks
Date: Fri, 09 Sep 2022 01:47:04 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-99097.20220909014704.13618@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19002.20220909011236.13618@ruby-lang.org
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/
prev parent reply other threads:[~2022-09-09 1:47 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
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) [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-99097.20220909014704.13618@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).