OneBite.Dev - Coding blog in a bite size

capitalize a string in Ruby

Code snippet on how to capitalize a string in Ruby

string = "hello world"
string.upcase

This code snippet shows how to capitalize a string in Ruby. The first line creates a variable called string and assigns it to the string “hello world”. Then, the second line calls the upcase method on the string which capitalizes any letter in the string and returns the new capitalized string. The original variable remains unchanged. As a result, the code will return the capitalized string “HELLO WORLD”.

ruby