def titleize(string)
string.split(" ").map {|word| word.capitalize}.join(" ")
end
This titleizes every single word, but how do I capture certain words I don't want capitalized?
ie) Jack and Jill
And please DO NOT USE Regex.
UPDATE:
I am having trouble making this code work: I got it to print an array of words all caps, but not without the list below.
words_no_cap = ["and", "or", "the", "over", "to", "the", "a", "but"]
def titleize(string)
cap_word = string.split(" ").map {|word| word.capitalize}
cap_word.include?(words_no_cap)
end
string.split
does in fact use the regex. You likely want smth already prepared for use—then take a look at titleize. It may be installed as gem. – Edgewise