How do I take a string and convert it to lower or upper case in Ruby?

How do I take a string and convert it to lower or upper case in Ruby?

The simplest way to convert a string to lowercase is to use the downcase method:

'HELLO'.downcase # => 'hello'

The simplest way to convert a string to uppercase is to use the upcase method:

'hello'.upcase # => 'HELLO'

If you need to convert a string to titlecase (the first letter of each word is uppercase), you can use the titlecase method:

'hello world'.titlecase # => 'Hello World'

If you need to convert a string to a capitalized form (the first letter is uppercase, the rest is lowercase), you can use the capitalize method:

'hello world'.capitalize # => 'Hello world'