From: Matt Harrison Date: 2008-12-28T20:20:51+09:00 Subject: Re: Syntax error I don't understand Albert Schlef wrote: > (I'm using Ruby 1.8.6.) > > I'm trying to add a random number to an array. I do: > > a = [] > a << rand 3 > > But ruby replies with "syntax error, unexpected tINTEGER, expecting kDO > or '{' or '('" > > Why's that? > > When I add parentheses to the function call, as in... > > a = [] > a << rand(3) > > ...then I don't get this syntax error. I'd like to understand why this > happens. As I have learned, the parenthesis are optional for function arguments, however there are some cases where that confuses the interpreter. It would be my guess ruby is trying to do "a << rand" and then finds and extra integer stuck on the end. Putting the parenthesis around the integer forces ruby to perform the "<<" on the whole function. HTH Matt