How to permanently capitalize a string in Ruby
Overview
Capitalizing a string in Ruby means changing the first letter of the string to upper case. The capitalize method is useful in this regard. However, capitalize! is the best method to change the string permanently.
Syntax
str.capitalize!
Parameters
None.
Return value
The value returned is the string with its first letter in the upper case.
Code
We will create some strings and capitalize them permanently. See the code example below:
# create stringsstr1 = "edpresso"str2 = "is"str3 = "the"str4 = "best"# capitalize thema = str1.capitalize!b = str2.capitalize!c = str3.capitalize!d = str4.capitalize!# print changed stringsputs str1puts str2puts str3puts str4