Where is Ruby's string literal juxtaposition feature officially documented?
UPDATE
This is now officially documented in the RDoc that ships with Ruby.
Changes will propagate to RubyDoc the next time they build the documentation.
The added documentation:
Adjacent string literals are automatically concatenated by the interpreter:
"con" "cat" "en" "at" "ion" #=> "concatenation"
"This string contains "\
"no newlines." #=> "This string contains no newlines."
Any combination of adjacent single-quote, double-quote, percent strings will
be concatenated as long as a percent-string is not last.
%q{a} 'b' "c" #=> "abc"
"a" 'b' %q{c} #=> NameError: uninitialized constant q
ORIGINAL
Right now, this isn't anywhere in the official ruby documentation, but I think it should be. As pointed out in a comment, the logical place for the docs to go would be: http://www.ruby-doc.org/core-2.0/doc/syntax/literals_rdoc.html#label-Strings
I've opened a pull request on ruby/ruby with the documentation added.
If this pull request is merged, it will automatically update http://www.ruby-doc.org. I'll update this post if/when that happens. ^_^
The only other mentions of this I've found online are:
- The Ruby Programming Language, page 47 (mentioned in another answer)
- Ruby Forum Post circa 2008
- Programming Ruby
Why does ruby automatically combine Strings?
Yes. From Literals: String
Adjacent string literals are automatically concatenated by the interpreter:
"con" "cat" "en" "at" "ion"
#=> "concatenation"
"This string contains " "no newlines."
#=> "This string contains no newlines."
Surprising string concatenation
This only works for string literals, and a part of the literal syntax.
If you have 2 string literals with just whitespace between them, they get turned into a single string. It's a convention borrowed from later versions of C.
String object to array ruby
"{1,22,33,444}".scan(/\d+/) #=> ["1", "22", "33", "444"]
should do it.
Why do two strings separated by space concatenate in Ruby?
Implementation details can be found in parse.y
file in Ruby source code. Specifically, here.
A Ruby string
is either a tCHAR
(e.g. ?q
), a string1
(e.g. "q", 'q', or %q{q}), or a recursive definition of the concatenation of string1
and string
itself, which results in string expressions like "foo" "bar"
, 'foo' "bar"
or ?f "oo" 'bar'
being concatenated.
quickstart jboss (or tomcat) + beans tutorial
EJB 3 Tutorial explaining Ant and showing how to create a session and entity beans with annotations and JBoss
Related Topics
How to Test If a String Is Basically an Integer in Quotes Using Ruby
Combining Implicit Wait and Explicit Wait Together Results in Unexpected Wait Times
How to Create Multiple Submit Buttons For the Same Form in Rails
No Increment Operator (++) in Ruby
What Is the Best Method of Handling Currency/Money
How to Update Ruby Gems from Behind a Proxy (Isa-Ntlm)
Difference Between Class Variables and Class Instance Variables
Ruby: String Comparison Issues
Difference Between \A \Z and ^ $ in Ruby Regular Expressions
Rvm Installation Not Working: "Rvm Is Not a Function"
Sudo Gem Install' or 'Gem Install' and Gem Locations
How to Track System-Specific Config Files in a Repo/Project
How to Set Tls Context Options in Ruby (Like Openssl::Ssl::Ssl_Op_No_Sslv2)
Sort an Array According to the Elements of Another Array
What Does the Question Mark At the End of a Method Name Mean in Ruby