Browse code

Improved, I think, the Titlecase plugin

J. B. Rainsberger authored on 27/11/2011 at 23:24:20
Showing 1 changed files
... ...
@@ -11,8 +11,8 @@ class String
11 11
     # capitalize first and last words
12 12
     x.first.to_s.smart_capitalize!
13 13
     x.last.to_s.smart_capitalize!
14
-    # small words after colons or periods are capitalized
15
-    x.join(" ").gsub(/(:|\.)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " }
14
+    # small words are capitalized after colon, period, exclamation mark, question mark
15
+    x.join(" ").gsub(/(:|\.|!|\?)\s?(\W*#{small_words.join("|")}\W*)\s/) { "#{$1} #{$2.smart_capitalize} " }
16 16
   end
17 17
 
18 18
   def titlecase!