I am learning Ruby at the moment, and I came across this strange situation.
When I run the following code, I get the output shown below.
Work code:
def hello(a,b=1,*c,d,e,f) pa,b,c,d,e,f end hello(1,2,3,4,5)
Working code output:
1 2 [] 3 4 5
However, when editing the code so that the 'e' parameter is the catch all parameter, I get the error below.
Failure Code:
def hello(a,b=1,c,d,*e,f) pa,b,c,d,e,f end hello(1,2,3,4,5)
Code exit error:
a.rb:1: syntax error, unexpected * def hello(a,b=1,c,d,*e,f) ^ a.rb:1: syntax error, unexpected ')', expecting '=' a.rb:3: syntax error, unexpected keyword_end, expecting end-of-input
I am using ruby ββ2.3.1p112 (2016-04-26 version 54768) on Ubuntu.
I am interested to know why the second piece of code does not work.
Edit:
The following code also does not work.
def hello(a,b=1,c,d,e,*f) pa,b,c,d,e,f end hello(1,2,3,4,5)
And I get a similar error
a.rb:1: syntax error, unexpected * def hello(a,b=1,c,d,e,*f) ^ a.rb:3: syntax error, unexpected keyword_end, expecting end-of-input