0

I'm trying to test out some of the code I write from a book, and created a ruby script to do so.

Right now, I'm supposed to use either shift, push, pop, or unshift to reverse the order of a string.

To do this, I wrote ->

#!/usr/bin/env ruby
def reverse(string)
    reverse = []

    string.split.each do | char | 
        reverse.unshift(char)
    end

    reverse.join
end

reverse("Hello")

When I run the script in command line though, nothing returns ->

Stepans-MacBook-Pro-2:atlas stepan$ /Users/stepan/Desktop/ruby_tester.rb 
Stepans-MacBook-Pro-2:atlas stepan$ 

What's happening here?

1 Answer 1

1

You need to output the response. Try puts reverse("Hello").

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.