Controlling Case


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

Problem

You need to modify the case of a string, up, down, or capitolized.

Solution

s = "this Is A weird Sentence"
  ==>"this Is A weird Sentence"
s.upcase     # uppercase
  ==>"THIS IS A WEIRD SENTENCE"
s.downcase   # lowercase
  ==>"this is a weird sentence"
s.capitalize # capitalize first word, downcase rest
  ==>"This is a weird sentence"
s.swapcase   # reverse the case of each alpha character
  ==>"THIS iS a WEIRD sENTENCE"
# don't forget all of the bang equivalents (eg upcase!)
exit

Discussion

The string class has a full complement of modification methods including upcase, downcase, capitalize, and swapcase. Each one of those also has a "bang version" (a ruby method-naming idiom where it modifies the object in place rather than returning a modified copy).

Contrast

Status: In Progress