Skip to content

Instantly share code, notes, and snippets.

@fresh5447
Created February 19, 2014 21:31
Show Gist options
  • Save fresh5447/9102056 to your computer and use it in GitHub Desktop.
Save fresh5447/9102056 to your computer and use it in GitHub Desktop.
Loops - Title Case
class String
def title_case
array_of_words = self.downcase.split
list_of_articles = ["the", "of", "and", "a"]
array_of_words.each do |word|
unless list_of_articles.include? word
word.capitalize!
end
end
array_of_words.first.capitalize!
array_of_words.join(" ")
end
end
#word.capitalize! unless list_of_articles.include?(word)
"the great gatsby?".title_case
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment