Mark Hubbart
12/22/2004 5:21:00 PM
On Thu, 23 Dec 2004 01:03:55 +0900, Zsban Ambrus <ambrus@math.bme.hu> wrote:
> > irb(main):006:0> puts("foo"
> > irb(main):007:1> "bar")
> > SyntaxError: compile error
> > (irb):7: syntax error
> > "bar")
> > ^
> > (irb):7: syntax error
> > from (irb):7
>
> What I find even more wierd is this warning:
>
> irb(main):001:0> $-v=1
> => 1
> irb(main):002:0> puts(("foo"
> irb(main):003:2> "bar"))
> (irb):2: warning: unused literal ignored
> bar
> => nil
I'm not sure what's so weird about that... Putting a newline between
the strings makes them into two separate statements, ruining the
concatenation. The statement above is functionally the same as this:
puts(("foo";"bar"))
With the two string literals being in separate statements, ruby sees
no link between the two statements, so the first literal gets created,
then ignored. With a continued line, or explicit concatenation, it
should and does work.
As for the SyntaxError in the OP's message, this is (apparently)
because ruby sees it as two statements, and you can't have more than
one statement inside the method call parens. Doubling up on them
("puts((foo; bar))" cancels that out.
cheers,
Mark