In Ruby, we use the downcase
method to convert a string to lowercase. This method takes no parameters and returns the lowercase of the string that calls it. It returns the original string if no changes are made.
Note: This method does not affect the original string.
str.downcase
str
is the name of the string to convert.
This method requires no parameters.
This method returns the lowercase of the string that calls it, in this case, str
. It returns the original string if there is no conversion.
# create stringsstr1 = "WELCOME"str2 = "to"str3 = "EDpreSSO"# downcase stringsa = str1.downcaseb = str2.downcasec = str3.downcase# print resultsputs aputs bputs cputs str1puts str2puts str3
In the code above, we create some strings and convert them to lowercase using the downcase
method.
We also notice from the code above that nothing changes for the string str2
. This is because it is already in lowercase.
Also, observe that no changes are made to the original string.