Skip to content

Instantly share code, notes, and snippets.

@xander-miller
Created February 19, 2014 17:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xander-miller/9096851 to your computer and use it in GitHub Desktop.
Save xander-miller/9096851 to your computer and use it in GitHub Desktop.
class String
def title_case
articles = ['a','the','of']
words_array = self.downcase.split(" ")
words_array.each do |word|
unless articles.include?(word)
word.capitalize!
end
end
words_array.first.capitalize!
words_array.join(" ")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment