1 = "hello, I'M ray"
2 puts s.upcase
3 puts s.downcase
4 puts s.capitalize
5 puts s.swapcase
6 puts s

Output: HELLO, I'M RAY
    hello, i'm ray
    Hello, i'm ray
    HELLO, i'm RAY
    hello, I'M ray

 

The upcase and downcase methods force all letters in the string to upper-or lowercase, respectively. The swapcase method transforms uppercase letters into lowercase letters and vice versa. The capitalize method makes the first character of the string uppercase, if it's a letter, and makes all other letters in the string lowercase.

All four methods have corresponding methods that modify a string in place rather than creating a new one: upcase!, downcase!, swapcase!, and capitalize!.

 

To change the case of specific letters while leaving the rest alone, you can use the TR or TR! methods, which translate one character into another:

 

1 puts 'hello sunshine'.tr('hs''HS')
2 = 'hello sunshine'
3 s.tr!('hs''HS')
4 puts s

Output: Hello SunSHine
    Hello SunSHine