Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

ruby
string
lowercase
communitycreator

How to convert a string to lowercase in Ruby

okwudili onyejiaku

Overview

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.

Syntax

str.downcase

str is the name of the string to convert.

Parameters

This method requires no parameters.

Return value

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.

Code example

# 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
Convert strings to lowercase using downcase method in Ruby

Explanation

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

ruby
string
lowercase
communitycreator
RELATED COURSES

View all Courses

Keep Exploring