How to concatenate the strings in Ruby
In this tutorial, we are going to learn about how to concatenate the strings in Ruby.
Concatenation means the joining of two or more strings into a single string.
Using ”+” operator
To concatenate the two strings into a single string, we can use the addition operator +
in Ruby.
Here is an example:
first = "alex"
second = "pop"
full_name = first + second
puts full_name
Output:
"alexpop"
Similary, we can also append a string to an existing string using the concat()
method in Ruby.
name = "alex"
name.concat("pop")
puts name