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.
Summary
Build a method that reverses the characters in a string without using the
reverse
method.
Exercise File
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.
Solution
Can be found on the solutions branch on github.