From: "David A. Black" Date: 2008-05-11T00:25:08+09:00 Subject: Re: "capitalize" also letters after "-" ? --1926193751-363207204-1210433108=:8738 Content-Type: MULTIPART/MIXED; BOUNDARY="1926193751-363207204-1210433108=:8738" This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --1926193751-363207204-1210433108=:8738 Content-Type: TEXT/PLAIN; charset=X-UNKNOWN; format=flowed Content-Transfer-Encoding: QUOTED-PRINTABLE On Sat, 10 May 2008, I=C3=B1aki Baz Castillo wrote: > Hi, I receive strings like: > > content-language > accept-resource-priority > > and I want to "capitalize" them in this way: > > Content-Language > Accept-Resource-Priority > > But String#capitalize method just capitalized first letter: > > Content-language > Accept-resource-priority > > > Is there any "fast" method for what I want? > Yes, I could implement it extending String class or my own class < String= , but > performance is very important and I'd prefer using a method written in C > (as "String#capitalized"). Does is exist? I have to express healthy skepticism as to whether performance is *so* critical that you can't just do: str.gsub!(/((^|-).)/) { $1.upcase } and if it is, then I'll express healthy skepticism as to whether or not Ruby is the right language for the job :-) I don't know of any C library that does the above, so if you need it, you should probably go ahead and write it. You can base it off rb_capitalize(_bang). David --=20 Rails training from David A. Black and Ruby Power and Light: INTRO TO RAILS June 9-12 Berlin ADVANCING WITH RAILS June 16-19 Berlin INTRO TO RAILS June 24-27 London (Skills Matter) See http://www.rubypal.com for details and updates! --1926193751-363207204-1210433108=:8738-- --1926193751-363207204-1210433108=:8738--