Ruby Language Strings Case manipulation

Help us to keep this website almost Ad Free! It takes only 10 seconds of your time:
> Step 1: Go view our video on YouTube: EF Core Bulk Extensions
> Step 2: And Like the video. BONUS: You can also share it!

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.


Got any Ruby Language Question?