Strings in Ruby - Concatenating Strings (Page 3 of 4 )
In Ruby, you can add on to an existing string with various concatenation techniques. With Ruby, you don’t have to jump through the hoops that you might if you were using a language with immutable strings.
Adjacent strings can be concatenated simply because that they are next to each other:
"Hello," " " "Matz" "!" # => "Hello, Matz!"
You can also use the+ method:
"Hello," + " " + "Matz" + "!" # => "Hello, Matz!"
You can even mix double and single quotes, as long as they are properly paired.
Another way to do this is with the<<method. You can add a single string:
"Hello, " << "Matz!" # => Hello, Matz!
Or you can chain them together with multiple calls to<<: