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 strings str1 = "WELCOME" str2 = "to" str3 = "EDpreSSO" # downcase strings a = str1.downcase b = str2.downcase c = str3.downcase # print results puts a puts b puts c puts str1 puts str2 puts 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.
RELATED TAGS
CONTRIBUTOR
View all Courses