Running the Ruby Koans within Visual Studio
I’m (finally) learning Ruby since a couple of days ago, and I found a great resource: the Ruby Koans. It’s basically a set of failing unit tests that you have to make pass, and by doing so you learn different aspects of the language. I wanted to edit the koans in Visual Studio using the support added by the IronRuby project, because I don’t want to pay for an editor or work in a bad one, but I wanted to run the koans with the standard Ruby executable because IronRuby’s support for Ruby 1.9 is not complete yet. And of course, I wanted to work without having to leave VS at all. Here are the steps I followed.
The first step is to create a new Visual Studio project, an IronRuby console application, and add the koans to it:

The next step is to setup an external tool to run the koans (Tools –> “External Tools…”):

When I installed Ruby using RubyInstaller I chose to add the Ruby executable to my path, so I only have to type “ruby.exe” in the command field. If the executable is not in your path you just need to specify the full route. The argument is the full path to the path_to_enlightenment.rb file, which is the one that guides you through the whole process. I marked the “Use Output window” option so I would see the output within Visual Studio. The last step is to assign a shortcut to the external tool so we can run it more easily. Go to Tools –> Options, and then to Environment –> Keyboard. In “Show commands containing” type “ExternalCommand”:

In my case I put the Ruby external tool in the first place of the Menu Contents list, so the command I’m looking for is “Tools.ExternalCommand1”:
I chose the “Ctrl + Shift + Q” shortcut, mainly because pretty much anything else was taken. Now we are all set, just hit your shortcut and begin the path to enlightenment!
This approach is also useful if you want to run your own source file (for instance, if you are typing code snippets from a book you are reading). In that case just use $(ItemFileName) (“Item File Name”) in the external tool configuration instead of “path_to_enlightenment.rb”. Again the goal is to edit the source code files in Visual Studio and run them with the latest Ruby version.