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.)
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.)