OneBite.Dev - Coding blog in a bite size

combine two strings in Ruby

Code snippet on how to combine two strings in Ruby

string_1 = "Hello"
string_2 = "World"

combined_string = string_1 + " " + string_2

puts combined_string

This code creates two strings, string_1 and string_2, and assigns them each a value of “Hello” and “World” respectively. Then, it uses the ’+’ operator to combine the two strings, adding a space in between for readability. Finally, it puts (or prints) the combined string to the output. The result should be “Hello World” printed to the console.

ruby