Ironing code, geek t-shirts and even presentations!


How to Debug and Run IronRuby Code From Visual Studio

This isn't a trivial thing to do until the IronRuby Visual Studio Integration component is out. So here are the steps in order to achieve that:

1. In Visual Studio, click on File-> Open -> Project/Solution

How to Debug and Run IronRuby Code From Visual Studio

2. Select ir.exe from the [IronRuby code directory]\trunk\build\debug (or release, depends on how you've compiled the code)

How to Debug and Run IronRuby Code From Visual Studio

3. Right click ir.exe in Solution Explorer and select Properties

How to Debug and Run IronRuby Code From Visual Studio

4. In Command Arguments, with "-D [path to code file]" where [path to code file] will be the full path to your ruby file.
For example, -D "c:\dev\IronRubyTest\test.rb".

How to Debug and Run IronRuby Code From Visual Studio

That's it! you can debug your IronRuby code file now!


This post was greatly inspired by the IronPython solution that was posted by Harry Pierson on his blog.


IronRuby Tip: Access .Net Indexers

The Problem

IronRuby Tip: Access .Net Indexers  Currently, if you have a .Net class you want to access via IronRuby, and you have an indexer there (like myObject[2]), you won't be able to use the indexer with brackets [] from IronRuby. You'll get an exception.

The Solution

Use get_Item(index) instead (pay attention to casing).


my_dataset.Tables[0] # <-- This won't work
my_dataset.Tables.get_Item(0) # <-- This will work great!
All the best,

Why IronRuby is AWSOME!

Yesterday I had to detach a folder from the SVN supervision. In order to do that, one needs to delete the .svn folders within the folder and its subfolders.
I decided to take advantage of IronRuby for that matter.

The problem I ran into with this one was that the files on the .svn folder were read-only. This means that in order to delete the folder, I first have to loop over all the files and remove their read-only attribute. I searched the net for a way to do that without such a loop and found a solution that used a WMI request.

IronRuby lets me take the benefit of the great System.Management class and use it in a Ruby script that I can write in no time.

Here is the code that I've ended up with:

require 'mscorlib'
require 'System.Management, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a'

def RemoveSvnFromDir(path)
    # loop over the files in the given path
    Dir.foreach(path) do |filename|
        current_dir = path + "\\" + filename

        # Ignore dot and double-dot.
        next if filename == "." || filename == ".."

        # If the file is the svn folder, remove it using WMI (no need to reset the read-only attributes)
        if filename == ".svn"
                puts "Removing #{current_dir}"
                dir ="win32_Directory.Name='#{current_dir}'")
                dir.InvokeMethod("Delete", nil,nil);                
            rescue Exception => e
                puts e.to_s
        # If this is a folder, recourse into it and detach it from SVN as well

# Get the path from the command line and execute
dir_name = ARGV[0]
puts "Detaching SVN from #{dir_name}"

In order to run it, all that is needed is to open cmd and write "ir SVNCleaner.rb c:\MyCodeDirectory" (assuming that the script file is named SVNCleaner.rb).

This is just a small example of the great power that uniting .Net and dynamic languages can unleash, get ready for more!

Happy Succoth!