Iterating and Incrementing Strings in Ruby (Page 1 of 6 )
From a String to an Array
Conveniently, split converts a string to an array. The first call to splitis without an argument:
"0123456789".split # => ["0123456789"]
That was easy, but what about splitting up all the individual values and converting them into elements? Do that with a regular expression (//) that cuts up the original string at the junction of characters.
You can capitalize a word, sentence, or phrase with capitalize or capitalize!. (By now you should know the difference between the two.) Here is a pair of sentences that are under the influence of capitalize:
"Ruby finally has a killer app. It's Ruby on Rails.".capitalize # => "Ruby finally has a killer app. it's ruby on rails."
Notice that the second sentence is not capitalized, which doesn’t look so good. Now you can see thatcapitalizeonly capitalizes the first letter of the string, not the beginning of succeeding sentences. Plan accordingly.