Skip to content

Instantly share code, notes, and snippets.

@ngn999
Created August 27, 2013 05:57
Show Gist options
  • Save ngn999/6350071 to your computer and use it in GitHub Desktop.
Save ngn999/6350071 to your computer and use it in GitHub Desktop.
title case
def title_case(title, minor_words='')
minor_list = minor_words.split.map {|x| x.downcase}
words = title.split
result = []
return '' if words == []
result << words[0].capitalize
words[1..-1].each do |elem|
if minor_list.include?(elem.downcase())
result << elem
else
result << elem.capitalize
end
end
return result.join(' ')
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment