运行Ruby脚本时无法在命令行上返回

时间:2021-12-26 07:05:12

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

我正在尝试测试我从书中编写的一些代码,并创建了一个ruby脚本来执行此操作。

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

现在,我应该使用shift,push,pop或unshift来反转字符串的顺序。

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 个解决方案

#1


1  

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

您需要输出响应。尝试反向(“你好”)。

#1


1  

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

您需要输出响应。尝试反向(“你好”)。