Created
June 3, 2015 18:11
-
-
Save hiendinhngoc/a17bdd11c209b45e6913 to your computer and use it in GitHub Desktop.
titlelize with the first little word
This file contains hidden or 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 titleize(string) | |
lowercase_word = %w{a an the and but or for nor of} | |
"#{string}".split.each_with_index.map{|x, index| lowercase_word.include?(x) && index > 0 ? x : x.capitalize}.join(" ") | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment