zenspider.com
(For all intents and purposes, this project is dead, but let us just call it "Deferred Indefinitely". Shall we?)

Problem

You want to reverse a string either by every word, or every character.

Solution

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

Discussion

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.

Contrast

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.

TODO: LIST_OF_RELATED_ITEMS

Status: In Progress