I'm trying to split a string to capitalize each word.
Code:
def titleize(a)
little_words = %w(a an the)
#a = %w(a quick brown fox jumps) --> works if an array is specifically used.
a.split(" ")
a.each do |i|
if !little_words.include? "#{i}"
i.capitalize!
end
end
g = a.join(" ")
return g
end
print titleize("a quick brown fox jump")
Error:
`titleize': undefined method `each' for "a quick brown fox jump":String (NoMethodError)
However, I am running into this error. From what I understand, the error is saying that my variable 'a' is a string which does not contain the method 'each'. I have already applied 'split(" ")' to convert the string to an array. Why does it not work?