Ruby String.capitalize for all words

So, I was trying to uppercase the first letter of all the words in a string. For example:
'the example string' -> 'The Example String'
So I had a look around and found this great little snippet of code:
'the example string'.gsub(/\b\w/){$&.upcase}
Check out the original post here: http://snippets.dzone.com/posts/show/4702
Laters,
J.

Posted by neomorphic Sun, 10 Feb 2008 00:58:00 GMT



weewar.com corner