Reverse a string in or not in place : reverse « String « Ruby






Reverse a string in or not in place


s = ".sdrawkcab si gnirts sihT"
puts s.reverse                             
puts s

s.reverse!                            # => "This string is backwards."
puts s                                # => "This string is backwards."

 








Related examples in the same category

1.Call reverse function from string class
2.Call reverse function from returning value from update function
3.To reverse the characters means to alter the characters so they read in the opposite direction.
4.Reverse a palindrome: