capitalize composed name ruby
To capitalize a composed name in Ruby, you can follow these steps:
Define the composed name as a string variable:
ruby composed_name = "john doe"
Split the composed name into individual words:
ruby words = composed_name.split(" ")
The split
method is used to split the string at each space character, creating an array of words.
- Capitalize the first letter of each word:
ruby capitalized_words = words.map { |word| word.capitalize }
The map
method is used to iterate over each word in the array and apply the capitalize
method to capitalize the first letter of each word.
- Join the capitalized words back into a single string:
ruby capitalized_name = capitalized_words.join(" ")
The join
method is used to join the words in the array back into a single string, using a space character as the separator.
- Print the capitalized name:
ruby puts capitalized_name
The puts
method is used to output the capitalized name to the console.
By following these steps, you can capitalize a composed name in Ruby without using any personal words or sentences at the beginning or end of the response.