implicit string concatenation

D

Dafydd Harries

I recently encountered some unexpected behaviour in the way Ruby
implicly concatenates strings (or, in this case, doesn't). Allow me to
use an IRB session to illustrate:

irb(main):001:0> puts("foo" "bar")
foobar
=> nil
irb(main):002:0> puts(
irb(main):003:1* "foo" "bar")
foobar
=> nil
irb(main):004:0> puts("foo" \
irb(main):005:1* "bar")
foobar
=> nil
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's the rationale for this?

In order to work around this, I had to either use a backslash to
explicitly continue the line or explicitly concatenate the strings using
"+".

(In case it's significant, I'm using Ruby on a Debian unstable system
and the version is 1.8.2pre3, modulo some patches.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top