Skip to content

Instantly share code, notes, and snippets.

/strings Secret

Created May 5, 2015 18:12
Show Gist options
  • Save anonymous/3dd8b30dad6a6faedfa8 to your computer and use it in GitHub Desktop.
Save anonymous/3dd8b30dad6a6faedfa8 to your computer and use it in GitHub Desktop.
def titleize(s)
words = s.split.map do |word|
if %w(the and over).include?(word)
word
else
word.capitalize
end
end
words.first.capitalize!
words.join(" ")
end
title ("jaws") ===> Jaws
title ("david copperfield") ===> David Copperfield
title ("war and peace") ===> War and Peace
title ("bride over the river kwai") ===> Bridge over the River Kwai
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment