append a string to the end of another string in ruby

In Ruby, to append a string to another string you can use the + operator or the << operator. Here is an example:

main.rb
string_one = "Hello"
string_two = "World"
string_one += " " + string_two
# or string_one << " " << string_two
puts string_one
# Output: Hello World
148 chars
7 lines

Both methods will concatenate the two strings and store the result in the string_one variable. The puts method will then output the result to the console.

related categories

gistlibby LogSnag