ucwords

The ucwords() function turns the first character of each word in a string to upper-case, if the first character is alphabetic.

PHP

echo ucwords("ruby is easy.");
=> // Ruby Is Easy. 

Ruby doesn’t have a function which can capitalize all the words in a string – so to accomplish this it’s a little bit harder. You need to split the string into words, then capitalize the first character of each word, and then finally join all the words back into a string.

Ruby

puts "ruby is easy.".split(' ').select {|w| w.capitalize! || w }.join(' ');
=> # Ruby Is Easy. 
By | 2009-08-03T16:17:16+00:00 July 13th, 2009|Categories: PHP, Ruby|Tags: , , , , , |1 Comment

About the Author:

One Comment

  1. Rasidee January 14, 2010 at 3:09 am

    puts “ruby is easy”.gsub(/\b\w/){|s|s.upcase}
    => “Ruby Is Easy”

Comments are closed.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.

This Is A Custom Widget

This Sliding Bar can be switched on or off in theme options, and can take any widget you throw at it or even fill it with your custom HTML Code. Its perfect for grabbing the attention of your viewers. Choose between 1, 2, 3 or 4 columns, set the background color, widget divider color, activate transparency, a top border or fully disable it on desktop and mobile.