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 = array.new

last_letter = string_array.pop

if string_array.length > 0
new_word.push(last_letter)
else return new_word.join
end
end

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

reverse(help)
/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:
https://gist.github.com/psylone/90dd7746db15a1e1d8c8

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