在 sublime text 2 中执行 Ruby 代码
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11410158/
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
Execute Ruby code in sublime text 2
提问by vermin
How can I run a Ruby file with ST2 and see the ouput? I thought I should use the build command. But if I have this:
如何使用 ST2 运行 Ruby 文件并查看输出?我想我应该使用 build 命令。但如果我有这个:
def foobar
"hello world"
end
puts foobar
and then press cmd + shift + b. All I see is
然后按 cmd + shift + b。我看到的只是
[Finished in 0.1s]
In textmate I could use the cmd + r (run command) and see all the ouput from the ruby script.
在 textmate 中,我可以使用 cmd + r(运行命令)并查看 ruby 脚本的所有输出。
I'm I missing something?
我错过了什么吗?
回答by vermin
I didn't save the file. That's why it didn't work. To run a file without saving it first (like TextMate) you should try to use the Anypreter plugin.
我没有保存文件。这就是它不起作用的原因。要在不先保存文件的情况下运行文件(如 TextMate),您应该尝试使用 Anypreter 插件。
回答by Filipe Miguel Fonseca
I'm using windows here, but make sure you have selected the correct build system: "Tools > Build System > Ruby", then just press CTRL+B
我在这里使用 windows,但请确保您选择了正确的构建系统:“工具 > 构建系统 > Ruby”,然后只需按 CTRL+B
回答by Alphons
For future reference, hope it helps somebody:
以供将来参考,希望它可以帮助某人:
I came here with the same problem. (In Sublime Text 3) I followed the answers:
我带着同样的问题来到这里。(在 Sublime Text 3 中)我遵循了答案:
- selected ruby extention (bottom right in window)
- selected in menubar: Tools > Build System > Ruby
- save the file with a name
- pressed command + b
- 选定的 ruby 扩展名(窗口右下角)
- 在菜单栏中选择:工具 > 构建系统 > Ruby
- 用名称保存文件
- 按下命令 + b
and still saw:
仍然看到:
[Finished in 0.1s]
[Finished in 0.1s]
In the end the (stuppid) problem was: the console window was only one line big. So I only saw the last line, which is the note:
最后(愚蠢的)问题是:控制台窗口只有一行大。所以我只看到了最后一行,也就是注释:
[Finished in 0.1s]
[Finished in 0.1s]
solution: make the console window biggeret voila. I couldn't find any setting for that. So in the end I did that with the mouse Screenshot Sublime Text 3 - cropped
解决方案:使控制台窗口更大等等。我找不到任何设置。所以最后我用鼠标 截图 Sublime Text 3 - 裁剪
note the cursor (and ruby extention)
注意光标(和 ruby 扩展名)
回答by Boris
In summary a Sublime text has an "Automatic" Build System by default (after install) and you should changed it to a ruby or whatever language you use. Save the file and press ctrl + b (on windows) - should run the output into the ST console.
总之,默认情况下(安装后)Sublime 文本具有“自动”构建系统,您应该将其更改为 ruby 或您使用的任何语言。保存文件并按 ctrl + b(在 Windows 上) - 应该将输出运行到 ST 控制台。
回答by Jay Patel
enter control + ` (key close to number 1 in keyboard so it will open new window bottom of sublime text, where you can enter ruby code and see result), but make sure you have install ruby correctly and set your path from terminal
输入 control + `(键盘中靠近数字 1 的键,因此它将打开崇高文本的新窗口底部,您可以在其中输入 ruby 代码并查看结果),但请确保您已正确安装 ruby 并从终端设置路径

