私はこれに本当に近づいているように感じますが、なぜ機能しないのかわかり.join
ません。
これは私が書いたコードです:
class String
def title_case
title = self.split
title.each do |word|
unless (word.include?("of")) || (word.include?("the")) && (title.first != "the")
word.capitalize!
end
title.join(" ")
end
end
end
これが RSPEC です。
describe "String" do
describe "Title case" do
it "capitalizes the first letter of each word" do
"the great gatsby".title_case.should eq("The Great Gatsby")
end
it "works for words with mixed cases" do
"liTTle reD Riding hOOD".title_case.should eq("Little Red Riding Hood")
end
it "ignores articles" do
"The lord of the rings".title_case.should eq("The Lord of the Rings")
end
end
end