def foo
1,2
end
causes syntax error "unexpected ',', expecting keyword_end"
I'd think this is valid Ruby. What's wrong?
If you used explicit return it will work.
def foo
return 1,2
end
But that wouldn't work with implicit return. To make it work with implicit return you need to give it [1, 2].
return 1,2works. Going by Ruby convention of omitting return, I'd think just1,2would work.returnfollowed by a comma separated list to return an array. Similarly if you have an assignment with a single variable on the left hand side (or a*variable) then this can assign an array too e.g.x = 1, 2. But there isn't a general syntax to make an array without the square brackets.