ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:110628] [Ruby master Feature#19107] Allow trailing comma in method signature
@ 2022-11-07  1:19 byroot (Jean Boussier)
  2022-12-01  7:46 ` [ruby-core:111113] " matz (Yukihiro Matsumoto)
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: byroot (Jean Boussier) @ 2022-11-07  1:19 UTC (permalink / raw)
  To: ruby-core

Issue #19107 has been reported by byroot (Jean Boussier).

----------------------------------------
Feature #19107: Allow trailing comma in method signature
https://bugs.ruby-lang.org/issues/19107

* 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/

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

end of thread, other threads:[~2023-02-13  6:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` [ruby-core:111113] " matz (Yukihiro Matsumoto)
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

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