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?
str = "accept-resource-priority"
p str.split(/-/).map {|x| x.capitalize}.join("-")
Harry
···
On Sat, May 10, 2008 at 10:52 PM, Iñaki Baz Castillo <ibc@aliax.net> 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
···
On Sat, 10 May 2008, Iñaki 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?
--
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!
El Sábado, 10 de Mayo de 2008, Harry Kakueki escribió:
On Sat, May 10, 2008 at 10:52 PM, Iñaki Baz Castillo <ibc@aliax.net> 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?
>
>
> Thanks a lot.
>
>
> --
> Iñaki Baz Castillo
Is this too slow?
str = "accept-resource-priority"
p str.split(/-/).map {|x| x.capitalize}.join("-")
and if it is, then I'll express healthy skepticism as to whether or
not Ruby is the right language for the job
Good response
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).
ok, I'll keep this as an alternative
Thanks a lot.
···
El Sábado, 10 de Mayo de 2008, David A. Black escribió: