Project

General

Profile

Actions

Feature #19107

open

Allow trailing comma in method signature

Added by byroot (Jean Boussier) over 1 year ago. Updated about 1 year ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:110628]

Description

A popular style for multiline arrays, hashes or method calls, is to use trailing commas:

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 --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:

def foo(bar:,) # syntax error, unexpected ')'

Proposal

For consistency and convenience I propose to allow trailing commas in method declarations.


Related issues 2 (0 open2 closed)

Related to Ruby master - Bug #17858: Trailing comma after a `&block` parameter cause a syntax errorClosedActions
Related to Ruby master - Bug #3456: bisarre commaClosedmatz (Yukihiro Matsumoto)06/20/2010Actions
Actions

Also available in: Atom PDF

Like7
Like0Like0Like0Like0Like0Like0