macos 命令“ruby”在我的 Mac 上没有任何作用
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1899100/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The command "ruby" does nothing on my Mac
提问by Tom S.
I can't get the Ruby interpreter to run on either of my Macs (one MacBook and one MacBook Pro, both running Snow Leopard). When I run it, by typing ruby
in Terminal, nothing happens. It just sits there. I can kill it by pressing Ctrl+C
, but that's it. I know the Ruby process is running, since I can see it in Activity Monitor, and running ruby --version
works fine.
我无法让 Ruby 解释器在我的任何一台 Mac(一台 MacBook 和一台 MacBook Pro,都运行 Snow Leopard)上运行。当我运行它时,通过ruby
在终端中输入,没有任何反应。它只是坐在那里。我可以通过按 杀死它Ctrl+C
,但仅此而已。我知道 Ruby 进程正在运行,因为我可以在活动监视器中看到它,并且运行ruby --version
正常。
I have tried the following, all to no avail:
我尝试了以下方法,但都无济于事:
- I have some bash customizations, so I tried disabling them, but that didn't help.
- I installed a new copy of Ruby 1.8.7 using MacPorts, but that one had the same problem.
- I tried quitting and restarting the Terminal application.
- 我有一些 bash 自定义,所以我尝试禁用它们,但这没有帮助。
- 我使用 MacPorts 安装了 Ruby 1.8.7 的新副本,但那个有同样的问题。
- 我尝试退出并重新启动终端应用程序。
Some other information that might be useful:
其他一些可能有用的信息:
- I'm trying to run the version of Ruby that comes with Snow Leopard.
- I have installed Apple's developer tools.
- Other interpreters (Python, Io, etc.) work fine.
- 我正在尝试运行 Snow Leopard 附带的 Ruby 版本。
- 我已经安装了 Apple 的开发人员工具。
- 其他解释器(Python、Io 等)工作正常。
I spent a while tonight searching for this problem online, but haven't found any discussion of it. I'm at a loss for what could be causing it, so any help anybody can provide would be greatly appreciated.
我今晚花了一段时间在网上搜索这个问题,但没有找到任何讨论。我对可能导致它的原因一无所知,因此任何人都可以提供任何帮助将不胜感激。
回答by khelll
Ruby command itself will just behave the way you said, either provide it with script file or use the -e option:
Ruby 命令本身将按照您所说的方式运行,要么为它提供脚本文件,要么使用 -e 选项:
ruby -e ' puts "hello world" '
ruby -e ' puts "hello world" '
However I suspect that you want the IRB(interactive ruby). Run irb
in your shell.
但是我怀疑你想要 IRB(交互式红宝石)。irb
在你的 shell 中运行。
回答by Jordan Running
What are you trying to do, exactly? The ruby
command expects input, in most cases a file that contains Ruby code that you want it to run. In that case you have to specify the name of the file:
你到底想做什么?该ruby
命令需要输入,在大多数情况下是一个包含您希望它运行的 Ruby 代码的文件。在这种情况下,您必须指定文件名:
> ruby my_ruby_file.rb
If instead you want to run the interactive Ruby shell, i.e. the REPLconsole that you can type Ruby code into and have it executed each time you press enter, the command you want is irb
.
相反,如果您想运行交互式 Ruby shell,即您可以在其中键入 Ruby 代码并在每次按 Enter 键时执行的REPL控制台,您需要的命令是irb
.