Home »
Ruby Tutorial »
Ruby Programs
Ruby program to demonstrate the string concatenation
Last Updated : December 15, 2025
Problem Solution
In this program, we will demonstrate the different ways of string concatenation and print the string after concatenation.
Program/Source Code
The source code to demonstrate the string concatenation is given below. The given program is compiled and executed successfully.
# Ruby program to demonstrate the
# string concatenation.
# Concatenate using "+" operator.
MyStr1 = "Hello " + "World";
puts MyStr1;
# Concatenate using a single space.
MyStr2 = "Hello " "World";
puts MyStr2;
# Concatenate using "<<" operator.
MyStr3 = "Hello " << "World";
puts MyStr3;
# Concatenate using concat() method.
MyStr4 = "Hello ".concat("World");
puts MyStr4;
Output
Hello World
Hello World
Hello World
Hello World
Explanation
In the above program, we created string variables and assigned values by concatenating strings using different ways and printed the result.
Ruby Strings Programs »
Advertisement
Advertisement