You want to reverse a string either by every word, or every character.
Use String#reverse to reverse by character, or String#split and Array#reverse to reverse by every word:
newstring = string.reverse # by string newstring = string.split(/\s/).reverse.join(‘ ‘) # by word
While reverse will reverse a string character by character, ensuring that string.reverse.reverse is the same as string, the split method cannot make that assurance as we split on any whitespace, but join with a space.
TODO: look for cleaner methods.
Perl has a reverse function that works on arrays and strings. It also has split so the perl solution looks almost exactly like ruby’s solution.
Status: In Progress