OneBite.Dev - Coding blog in a bite size

convert a string to lowercase in Ruby

Code snippet on how to convert a string to lowercase in Ruby

str = "HELLO WORLD"
puts str.downcase

This code will convert a string to lowercase in Ruby. The first line defines a variable, str, and sets it to the string “HELLO WORLD”. The second line uses the “downcase” method on the str variable, which takes the string stored in the variable and converts it to all lowercase letters. Finally, the last line prints the modified string to the console.

ruby