ucwords
-
Ruby does not have a built-in method to capitalize all of the words within a string. We can accomplish this using the following example:
String#splitthe string into individual wordsEnumerable#selectto iterate through the wordsString#capitalize!each wordArray#jointhe words back into a single string
PHP
print ucwords("hello world"); // => Hello World
Ruby
"hello world".split(' ').select {|w| w.capitalize! || w }.join(' ') # => Hello World
Rails includes a built in
String#titleizemethod as part ofActiveSupportlibrary. This will perform the equivalent of the above Ruby.Rails
"hello world".titleize # => Hello World
see also
Looking for Rails or PHP web application development, integration, and training?
Rails for PHP is brought to you by Maintainable Software. Get custom web applications and personalized training from the authors of the book and website.

