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.
Here's an alternative using the xor bitwise operations:
class String def xor_reverse len = self.length - 1 count = 0 while (count < len) self[count] ^= self[len] self[len] ^= self[count] self[count] ^= self[len] count += 1 len -= 1 end self end "foobar".xor_reverse => raboof