Skip to Content
Learn
Introduction to Ruby
The '.reverse' Method

The .reverse method is called the same way .length is, but instead of asking Ruby to tell you how long a string is, it spits out a backwards version of the string you gave it. For instance,

"Eric".reverse

will result in

"cirE"

Reversing input can be useful if you want to sort a list of values from highest to lowest instead of lowest to highest. (We’ll get to sorting in later lessons.)

Instructions

1.

Call the .reverse method on your name. Don’t forget those quotation marks around your name to make it a string!

puts the answer to the console if you want to see the value.

Folder Icon

Take this course for free

Already have an account?