Argument forwarding requires parenthesis on method definitions
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?
Updated by byroot (Jean Boussier) 3 months 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) 3 months 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.
(...) anyway needs parenthesis on call sites (ambiguous with endless ranges otherwise), I personally think it makes sense to also have parens as a parameter.