I’d like to ask why having a splat param1 and a param2 with default value assignment in Ruby-1.9.3-p0 as below:
def my_method(*param1, param2 = "default"); end
returns
SyntaxError: (irb):1: syntax error, unexpected '=', expecting ')'
My workaround is explicitly wrap param1 in brackets like this:
def my_method((*param1), param2 = "default"); end
Many thanks
Ruby can’t parse a parameter with a default after a splat. If you have default assignment in a parameter after a splat, how would Ruby know what to assign the variable to?
Let’s say I then call my_method:
Ruby has no way of knowing whether b is missing, in which case you want b to be foo and a is [1,2,3], or if b is present in which case you want it to be 3.