In Ruby, we can use the reverse
method to reverse a string. The reverse
method reverses the characters of a string and returns a new string with the characters of the original string in reverse order.
str.reverse
str
: The string we want to reverse.The reverse
method returns a new string with the reversed characters of string str
.
# create some stringsstr1 = "Edpresso"str2 = "is"str3 = "awesome!"# reverse the stringsa = str1.reverseb = str2.reversec = str3.reverse# print resultsputs aputs bputs c
reverse
method on the strings that we created.