From: Yui NARUSE Date: 2011-06-03T22:17:36+09:00 Subject: [ruby-core:36719] [Ruby 1.9 - Feature #4822] String#capitalize improvements Issue #4822 has been updated by Yui NARUSE. Anurag Priyam wrote: > > You should use String#titleize provided by ActiveSupport. > > http://as.rubyonrails.org/classes/ActiveSupport/CoreExtensions/String/Inflections.html#M000381 > > But that capitalizes all the words in a string, no?. I am talking > about capitalizing the first letter of each sentence. Hmm, how about this? str.gsub(/\w.*?[.!?](?:\s+|\z)/){|c|c.capitalize} Of course, this is wrong for example "iPhone is designed by Apple in California." ---------------------------------------- Feature #4822: String#capitalize improvements http://redmine.ruby-lang.org/issues/4822 Author: Anurag Priyam Status: Open Priority: Normal Assignee: Category: Target version: I think it would be helpful if `String#capitalize` could capitalize _sentences_, and not just the first letter of a string. We could optionally pass a regexp to identify sentence boundaries. If we don't pass this parameter `capitalize` behaves as before. s = "hey all! wassup? i am good." # current capitalize s.capitalize #=> "Hey all! wassup? i am good." # new capitalize s.capitalize #=> "Hey all! wassup? i am good." s.capitalize(/[?!.] /) #=> "Hey all! Wassup? I am good." I am not sure what would it take to implement this. -- http://redmine.ruby-lang.org