Created
January 18, 2013 05:20
-
-
Save mfpiccolo/4562529 to your computer and use it in GitHub Desktop.
This program takes a sentence and capitalizes each word.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def title_case(sentence1) | |
if sentence1.kind_of? String | |
sentence1 = sentence1.downcase.split.to_a.map {|word| word.capitalize } | |
sentence1.join(" ") | |
else | |
"You should try and enter in a sentence." | |
end | |
end | |
puts "'#{title_case([2,3,4])}' should be 'You should try and enter in a sentence.'" | |
puts "'#{title_case("OK. NO WAY.")}' should be 'Ok. No Way.'" | |
puts "'#{title_case("where are you going?")} should be 'Where Are You Going?'" | |
puts "'#{title_case("hi")} should be 'Hi'" | |
puts "'#{title_case("HI")} should be 'Hi'" | |
puts "'#{title_case("tHiS Is A bIt OvErKiLl. BuT wHaT tHe HeLl.")} should be 'This Is A Bit Overkill. But What The Hell.'" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment