The downcase
and downcase!
methods are used to convert a string to lowercase.
The difference between the downcase!
and downcase
methods is that downcase
does not modify the string that calls it, but downcase!
permanently changes a string to lowercase. Therefore, if we want to permanently change a string to lowercase, we use the downcase!
method.
# no modification
str.downcase
# modification
str.downcase!
str
: The string that calls the method.The return value for both strings is a lowercase version of str
.
# create some stringsstr1 = "EDPRESSO"str2 = "IS"str3 = "AweSOME!"str4 = "AND"str5 = "EDUcative!"# downcase the# strings temporarilyputs str1.downcaseputs str1puts str2.downcaseputs str2puts str3.downcaseputs str3# downcase the# strings permanentlyputs str4.downcase!puts str4puts str5.downcase!puts str5
downcase
method on some of the strings and print the values of the strings and their downcase
.downcase!
method on the remaining strings and print the values of the strings and their downcase!
.When we run the code, only the strings that call the downcase!
method are permanently changed to lowercase, and the rest that call the downcase
method are not changed.