Ruby Language Case manipulation


Example

"string".upcase     # => "STRING"
"STRING".downcase   # => "string"
"String".swapcase   # => "sTRING"
"string".capitalize # => "String"

These four methods do not modify the original receiver. For example,

str = "Hello"
str.upcase # => "HELLO"
puts str   # => "Hello"

There are four similar methods that perform the same actions but modify original receiver.

"string".upcase!     # => "STRING"
"STRING".downcase!   # => "string"
"String".swapcase!   # => "sTRING"
"string".capitalize! # => "String"

For example,

str = "Hello"
str.upcase!  # => "HELLO"
puts str     # => "HELLO"

Notes:

  • prior to Ruby 2.4 these methods do not handle unicode.