How do you reverse a string in Ruby? I know about string#reverse. I\'m interested in understanding how to write it in pure Ruby, preferably an in-place solution.
def reverse(string) result = "" idx = string.length - 1 while idx >= 0 result << string [idx] idx = idx - 1 end result end