Iñaki Baz Castillo
5/10/2008 3:02:00 PM
El S=E1bado, 10 de Mayo de 2008, Harry Kakueki escribi=F3:
> On Sat, May 10, 2008 at 10:52 PM, I=F1aki Baz Castillo <ibc@aliax.net> wr=
ote:
> > 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?
> >
> >
> > Thanks a lot.
> >
> >
> > --
> > I=F1aki Baz Castillo
>
> Is this too slow?
>
> str =3D "accept-resource-priority"
> p str.split(/-/).map {|x| x.capitalize}.join("-")
Hummm:
Benchmark.realtime { "accept".capitalize }
=3D> 2.21729278564453e-05
Benchmark.realtime { "accept".split('-').map {|w|=20
w.capitalize}.join('-') }
=3D> 3.69548797607422e-05
=2D-=20
I=F1aki Baz Castillo