We can change lowercase characters in a string in Ruby to uppercase characters and vice versa using the swapcase
method.
str.swapcase
str: This is the string whose characters’ cases we want to swap.
# creates some stringsstr1 = "edpresso"str2 = "IS"str3 = "awESoMe"# swap casesputs str1.swapcaseputs str2.swapcaseputs str3.swapcase
str1
, str2
, and str3
are created and initialized with some values.swapcase
method is called on the strings we create. We then print the result.