Debugging 'reverse.rb' --- NoMethodError 'push'

Write a method that will take a string as input, and return a new

string with the same letters in reverse order.

Don’t use String’s reverse method; that would be too simple.

Difficulty: easy.

def reverse(string)
input = gets.strip
string_array = string.split(,)

new_word =

last_letter = string_array.pop

if string_array.length > 0
else return new_word.join

When I debug in mac terminal, i get the following:

/users/cyrilguirguis/Desktop/reverse.rb:17:in reverse': undefined methodpush’ for “)”:String (NoMethodError)
from /users/cyrilguirguis/Desktop/reverse.rb:25:in `’

I’m looking to review my code and provide a hint if my code is not
correct, and help me debug this specific nomethoderror problem.

Thank you for your time!

Here is the GitHub gist with the comments and explanation:

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs