Ruby: Methods

Everything in Ruby is an object and has specific built-in abilities knows as “methods”.

For eg strings have built-in methods that can tell you the length of the string, reverse it, capitalize it and much more.

.length method:

It returns the length of the string.

for eg:


Ruby will output =>> 6

.reverse method

This method reverse the string that we provide.

For eg:


Ruby will output => ahseyA

.upcase & .downcase

These two methods can be used to change the case of a string.

As the name suggests, .upcase would change the entire string to uppercase and .downcase would change the entire string to the lower case.

For eg:

puts “Ayesha”.downcase would give output =>> ayesha

puts “Ayesha”.upcase would give output =>> AYESHA