Saturday, 7 September 2013

.join method and .capitalize order in ruby

.join method and .capitalize order in ruby

In this titleize method, why do I get nil when I reverse the order of the
words.first.capitalize and words.join(" ") lines?
def titleize(x)
words = x.split(" ").collect do |word|
if %w(the and over).include?(word)
word
else
word.capitalize
end
end
words.first.capitalize!
words.join(" ")
end

No comments:

Post a Comment