January 15 - Reverse the Letters in a String Without Using the Reverse Method in Ruby
In this coding exercise you'll re-create the reverse method in Ruby. You are required to build a method that reverses the characters in a string and returns the reversed values.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Build a method that reverses the characters in a string without using the reverse method.

Exercise Description

You will need to perform monkey patching and open up the String class in Ruby. From there create a method called alt_reverse that reverses the characters in a string without calling the reverse method provided by Ruby.

Sample Use

"Hi there".alt_reverse # "ereht iH"

Real World Usage

In a real life program you would call the reverse method directly, so this method isn't necessary. However in this exercise you will:

  • Learn three important operations that can be performed on the String class in Ruby.
  • Implement monkey patching

Additionally, this is a common Ruby coding interview question that tests an applicant's knowledge of the String class.

Exercise File

Code File