To append a character to the beginning of a string in Ruby, you can use string concatenation with the `+` operator or the `prepend()` method.
In this example,
str1
with a value of "ello"
.+
operator to prepend the character 'H'
to str1
.str1 = "ello"
str1 = "H" + str1
puts str1
Hello
In this example,
str2
with a value of "orld"
.prepend()
method to prepend the character 'W'
to str2
.str2 = "orld"
str2.prepend("W")
puts str2
World
In this tutorial, we learned How to Append a Character to beginning of a String in Ruby language with well detailed examples.