Project

General

Profile

Actions

Bug #18267

closed

Argument forwarding requires parenthesis on method definitions

Added by tenderlovemaking (Aaron Patterson) about 1 month ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 3.1.0dev (2021-10-21T22:47:38Z master 844588f915) [x86_64-darwin20]
[ruby-core:105795]

Description

I like to write my method definitions without parenthesis. For example:

def foo bar
  # ...
end

I tried to use ..., but it doesn't work. For example if I do:

def call a, ...
  a.nil?(...)
end

It will be a syntax error, and the program exits. Can we make this syntax work so that I can always omit parenthesis?

Thank you!

Updated by matz (Yukihiro Matsumoto) about 1 month ago

I agree that this is a bug.

Matz.

Updated by byroot (Jean Boussier) about 1 month ago

It was known when the feature was introduced https://bugs.ruby-lang.org/projects/ruby-master/repository/git/revisions/d1ae2bc27fd4183e6abb9e83691e192bfe1e5316/diff, mame (Yusuke Endoh) added a NEWS entry specifically for it.

I presume it would clash with endless ranges?

Updated by Eregon (Benoit Daloze) about 1 month ago

[joke] Maybe a reason to be a little bit more consistent about Ruby syntax and always use parens for method definitions? :D [/joke]

Updated by Eregon (Benoit Daloze) about 1 month ago

On a more serious note, def= also has this restriction:

$ ruby -e 'def m(a) = 2'
OK
$ ruby -e 'def m a = 2'
-e:1: syntax error, unexpected end-of-input
$ ruby -e 'def m a = a'
-e:1: circular argument reference - a
-e:1: syntax error, unexpected end-of-input

Which I guess is trivially ambiguous because the = could be for an optional arg or for the method body.

Because (...) anyway needs parenthesis on call sites (ambiguous with endless ranges otherwise), I personally think it makes sense to also have parens as a parameter.

Actions #5

Updated by nobu (Nobuyoshi Nakada) about 1 month ago

  • Status changed from Open to Closed

Applied in changeset git|13a9597c7ca83fced5738e9345660ae6aef87eb7.


Argument forwarding definition without parentheses [Bug #18267]

Actions

Also available in: Atom PDF