Issue #4822 has been updated by Yui NARUSE.


Anurag Priyam wrote:
> > Hmm, how about this?
>  > str.gsub(/\w.*?[.!?](?:\s+|\z)/){|c|c.capitalize}
>  
>  This solves my problem better than what I was doing. Thanks. Do you
>  think that other's could also benefit from such an extension to
>  `capitalize`, or is it better done problem specific?

As my example, this can't be perfect.
Such function should be provided by third party, like gems.
----------------------------------------
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