나는이 문자와 정말 흡사하다고 느끼지만 왜 .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에 있습니다 : 당신이 코드의 형식이 경우, 당신은 당신이 #join
전화를 잘못 볼 것
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