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.
string = "This is my string"
string_arr = string.split('')
n = string_arr.length
new_arr = Array.new
17.times do |i|
new_arr << string_arr.values_at(n - i)
end
reversed_string = new_arr.flatten.join('')
=> "gnirts ym si sihT"