Skip to content

How to concatenate 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 + 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

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.