在 OS X 上轻松编辑和运行 Ruby
我从头开始使用 Ruby 来学习诀窍,但有一个快速查询。目前,我正在将一些小的测试代码写入
puts 'Hello World'
EditRocket,例如:等,另存为 test1.rb,然后在 Mac 上打开终端并使用以下命令执行“程序”:
ruby test1.rb
这是向后和向前变得有点乏味,所以我想知道是否有一种更“用户友好”的方法来编写一些 Ruby 代码,然后实时执行它以获得结果,就像在 SQL Server 中执行 SQL 代码一样?
I'm starting right from the beginning with Ruby to learn the ropes but have a quick query. Currently I am writing small test bits of code such as:
puts 'Hello World'
etc. into EditRocket, saving as test1.rb and then opening Terminal on my Mac and executing the 'program' with:
ruby test1.rb
This is becoming a little tedious with the backwards and forwarding so I was wondering if there was a more 'user friendly' approach to writing a bit of Ruby code and then executing it live to get a result as you would SQL code in SQL Server for example?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
在终端中运行 irb 将运行 Ruby 读取-评估-打印循环,该循环将评估您键入的每一行 Ruby。只需在终端中输入“irb”即可启动,然后在 irb 中输入“exit”即可退出。
Running irb in Terminal will run a Ruby read-eval-print loop that will evaluate each line of Ruby that you type. Just type "irb" in Terminal to start, and "exit" from within irb to exit.
尝试 irb,交互式 Ruby 解释器。
Try
irb
, the interactive Ruby interpreter.我推荐 TextMate 作为 Ruby 的文本编辑器。还有一个很棒的工具,称为 IRB,它是一个动态 Ruby 控制台。
I recommend TextMate as a text editor for Ruby. There is also a great tool called IRB, which is a dynamic Ruby console.
根据 EditRocket 网站:
使用 OS X,您可以为任何应用程序中的任何菜单创建自己的键盘快捷键。这是指南这样做。
编辑:下载该程序的试用版并运行它,似乎他们的文档是错误的或过时的,因为菜单选项是
Tools -> 。红宝石->执行程序
。此外,这相当乏味 - 每次您想要重新运行程序时,它都会打开一个不友好的对话框,允许您设置解释器和命令行参数等。我也建议您尝试(如果您喜欢的话,可以购买)TextMate;它是一个很棒的文本编辑器,并且运行 Ruby 的工作流程要好得多。
According to the EditRocket website:
With OS X, you can create your own keyboard shortcut for any menu in any application. Here's a guide on doing this.
Edit: Downloading a trial of this program and running it, it seems their documentation is wrong or outdated, as the menu option is
Tools -> Ruby -> Execute Program
. Further, this is rather tedious - it opens an unfriendly dialog each time you want to re-run the program allowing you to set the interpreter and command-line parameters, and more.I, too, recommend that you try out (and buy, if you like it) TextMate; it's a great text editor and it's workflow for running Ruby is far better.
由于其他人提到的原因,我喜欢 TextMate 进行简单的 Ruby 编码和我在此处发布的快速示例。
对于繁重的编码,我在 Mac OS 上使用 MacVim,或 Linux 或 Windows 上的 Vim 或 Gvim。它不是那么友好,但非常强大,而且到处都是相同的编辑器,包括使用相同的字体和主题以及我所做的自定义更改。
ActiveState 有 Komodo Edit,它是编辑器功能的完美结合,包括 vi 模式。它是免费的,因此您尝试它不会丢失任何东西。
I like TextMate for simple Ruby coding and quick examples that I post here, for the reasons mentioned by others.
For heavy coding I use MacVim on Mac OS, or Vim or Gvim on Linux or Windows. It's not as friendly but is extremely powerful, and, is the same editor everywhere, including using the same fonts and themes and custom changes I've made.
ActiveState has Komodo Edit, which is a really nice blend of editor features, including having a vi mode. It's free so you don't lose anything trying it.
您可能需要使用 Guard 来监视您的文件并在保存时运行它们。
You may want to use Guard to watch your files and run them whenever you save.