Improved, I think, the Titlecase plugin

This commit is contained in:
J. B. Rainsberger 2011-11-28 00:24:20 +01:00
parent 76af6980d4
commit 343e0f1409
1 changed files with 2 additions and 2 deletions

View File

@ -11,8 +11,8 @@ class String
# capitalize first and last words
x.first.to_s.smart_capitalize!
x.last.to_s.smart_capitalize!
# small words after colons or periods are capitalized
x.join(" ").gsub(/(:|\.)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " }
# small words are capitalized after colon, period, exclamation mark, question mark
x.join(" ").gsub(/(:|\.|!|\?)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " }
end
def titlecase!