This post originated from an RSS feed registered with Ruby Buzz
by Jeremy Voorhis.
Original Post: Parser Trivia
Feed Title: JVoorhis
Feed URL: http://feeds.feedburner.com/jvoorhis
Feed Description: JVoorhis is a Rubyist in northeast Ohio. He rambles about Ruby on Rails, development practices, other frameworks such as Django, and on other days he is just full of snark.
After reading Dave Fayram’s Ruby gotcha and _why’s splat tricks, I thought I’d contribute my own Ruby syntax discovery of the day: automatic string concatenation. As you can see, it only happens when you define two strings with quotes (of any kind) consecutively in one… err… statement? Methods returning strings do not apply.
irb(main):001:0>def thing() "thing" end
irb(main):002:0> thing
=> "thing"
irb(main):003:0> thing "string"
ArgumentError: wrong number of arguments (1 for 0)
from (irb):3:in `thing'
from (irb):3
irb(main):004:0> thing() "string"
SyntaxError: compile error
(irb):4: syntax error
thing() "string"
^
from (irb):4
irb(main):05:0> "string" thing()
SyntaxError: compile error
(irb):5: syntax error
"string" thing()
^
from (irb):5
irb(main):06:0> "string " "thing"
=> "string thing"