To append a character to the end of a string in Ruby, you can use the `<<` operator or the `concat` method.
In this example,
str1
with a value of "Hello World"
.<<
operator to append the character '!'
to str1
.str1 = "Hello World"
str1 << '!'
puts str1
Hello World!
In this example,
str2
with a value of "How are you"
.<<
operator to append the character '?'
to str2
.str2 = "How are you"
str2 << '?'
puts str2
How are you?
In this tutorial, we learned How to Append a Character to end of a String in Ruby language with well detailed examples.