Easily edit and run Ruby on OS X
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?
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.
Try irb
, the interactive Ruby interpreter.
I recommend TextMate as a text editor for Ruby. There is also a great tool called IRB, which is a dynamic Ruby console.
According to the EditRocket website:
Users can execute Ruby programs and view the standard and error output using the
Tools -> Execute Program -> Execute Ruby Program
menu option.
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.
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.
You may want to use Guard to watch your files and run them whenever you save.
精彩评论