How to Convert a String to Upper or Lowercase in Ruby

Written by on Jul 21 2016

Ruby’s string class offers a few methods to change the case of a string.

Upcase

Upcase is used to capitalize every letter of a string.

“michael”.upcase

returns: MICHAEL

Downcase

Downcase is used to make every letter in a string lowercase.

“MICHAEL”.downcase

returns: michael

Capitalize

Another method on the string class is capitalize. This method capitalizes the first letter of a string while downcasing the remaining letters.

“mICHAel”.capitalize

returns: Michael

Titleize

Titleize capitalizes every word in a string. Remember you can only use this if you are working within the Rails framework (or just the ActiveSupport gem).

name = “jaKe JoNes”
name.titleize

returns: Jake Jones

These are just a few methods on the String class. I suggest you read through this documentation to get familiar with all of the methods on String.

Meet
Michael

Hi I'm Michael,

I wrote the article you're reading... After spending a year in the jungles of Costa Rica, I had an epiphany and decided to pursue a career in software development. When I'm not pressing buttons on my keyboard you can find me experimenting with my one true love, Carolina BBQ. Mmmmmmm BBQ.

Get Blog Updates