From: "matz (Yukihiro Matsumoto)" <noreply@ruby-lang.org>
To: ruby-core@ml.ruby-lang.org
Subject: [ruby-core:111113] [Ruby master Feature#19107] Allow trailing comma in method signature
Date: Thu, 01 Dec 2022 07:46:11 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-100385.20221201074611.7941@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-19107.20221107011944.7941@ruby-lang.org
Issue #19107 has been updated by matz (Yukihiro Matsumoto).
I don't care for consistency here (since formal arguments and actual arguments are different).
I am not sure for convenience. Compare to actual arguments, there's less chance to rewrite/update formal arguments.
Is there an actual case where this proposal is convenient?
Matz.
----------------------------------------
Feature #19107: Allow trailing comma in method signature
https://bugs.ruby-lang.org/issues/19107#change-100385
* Author: byroot (Jean Boussier)
* Status: Open
* Priority: Normal
----------------------------------------
A popular style for multiline arrays, hashes or method calls, is to use trailing commas:
```ruby
array = [
1,
2,
3,
]
hash = {
foo: 1,
bar: 2,
baz: 3,
}
Some.method(
1,
2,
foo: 3,
)
```
The main reason to do this is to avoid unnecessary noise when adding one extra element:
```diff
diff --git a/foo.rb b/foo.rb
index b2689a7e4f..ddb7dc3552 100644
--- a/foo.rb
+++ b/foo.rb
@@ -1,4 +1,5 @@
Foo.bar(
foo: 1,
- bar: 2
+ bar: 2,
+ baz: 3
)
```
However, this pattern doesn't work with method declarations:
```ruby
def foo(bar:,) # syntax error, unexpected ')'
```
### Proposal
For consistency and convenience I propose to allow trailing commas in method declarations.
--
https://bugs.ruby-lang.org/
______________________________________________
ruby-core mailing list -- ruby-core@ml.ruby-lang.org
To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org
ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/
next prev parent reply other threads:[~2022-12-01 7:46 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-11-07 1:19 [ruby-core:110628] [Ruby master Feature#19107] Allow trailing comma in method signature byroot (Jean Boussier)
2022-12-01 7:46 ` matz (Yukihiro Matsumoto) [this message]
2022-12-01 8:51 ` [ruby-core:111122] " byroot (Jean Boussier)
2023-02-13 6:20 ` [ruby-core:112393] " rubyFeedback (robert heiler) via ruby-core
2023-02-13 6:43 ` [ruby-core:112394] " k0kubun (Takashi Kokubun) via ruby-core
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-100385.20221201074611.7941@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
--cc=ruby-core@ml.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).