The ELC Community Blog
A knowledge exchange on Ruby on Rails and Agile Development
IronRuby prealpha
by stevend on September 10, 2007
So let's start with something simple... how to get iron ruby installed. After searching around for bit, I found this binary on John Lam's Blog:
http://iunknown.typepad.com/IronRuby-Pre-Alpha1.zip
I downloaded and unzipped it. There's a build script which didn't work for me because some environment variables were not set correctly, so I went into the console, looked at what the build script should have been running and found msbuild in my .NET framework 2.0 directory:c:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\msbuild.exe /p:Configuration=Release /t:Rebuild IronRuby.sln
This worked perfectly, which got me very excited! I decided run to try out "rbx" next (the Microsoft version of IRB):
1 <pre>Build succeeded.
2 0 Warning(s)
3 0 Error(s)
4
5 Time Elapsed 00:00:08.69
6
7 PROMPT> cd bin\Release
8 PROMPT> rbx.exe
9 IronRuby Pre-Alpha (1.0.0.0) on .NET 2.0.50727.832
10 Copyright (c) Microsoft Corporation. All rights reserved.
11 >>>
12 </pre>
So far so good... but what can this ruby console really do? Let's push our luck!
1 <pre>>>> 2+2
2 => 4
3 >>> "hello" + "world"
4 => "helloworld"
5 >>> ["hello", "world"].join(" ")
6 => "hello world"
7 >>> ["hello", "world"].each do |elem|
8 ... puts elem
9 ... end
10 hello
11 world
12 => [hello, world]
13 </pre>
Wow! That worked exactly as I expected. Now let's watch things go downhill:
1 <pre>>>> h = {}
2 Ruby.Builtins.NotImplementedError: Exception of type 'Ruby.Builtins.NotImplementedError' was thrown.
3 >>> eval("puts 'hello'")
4 System.MissingMethodException: undefined local variable or method `eval' for #<object:0000002b>:Object
5 >>> " b ".strip
6 System.MissingMethodException: undefined local variable or method `strip' for b :MutableString
7
8 </object:0000002b></pre>
Class definitions are open:
1 >>> class TestKlass
2 ... def bob
3 ... puts "bob"
4 ... end
5 ... def joe
6 ... puts "joe"
7 ... end
8 ... end
9 => nil
10 >>> class TestKlass
11 ... def bob
12 ... puts "Fred"
13 ... end
14 ... end
15 => nil
16 >>> TestKlass.new.bob
17 Fred
18 => nil
19 >>> TestKlass.new.joe
20 joe
21 => nil
The source contains two major divisions, Microsoft.Scripting and Ruby. Inside Ruby, you can see the progress the project has made so far in converting ruby objects and constructs to be available in IronRuby.

Finally, let's examine what we can do by taking advantage of the common language runtime (CLR) to access libraries in another language
1 <pre>>>>
2 >>> require 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089'
3 => true
4 >>> require "System.Windows.Forms"
5 => true
6 >>> System::Windows::Forms::MessageBox.show "hello"
7 => #<dialogresult:0000002c> # messagebox showed up!
8 >>> System::Net::WebRequest.Create("http://www.google.com/")
9 System.MissingMethodException: No overload of method `Create' matches the specified argument types
10 at _stub_##22(Object[] , DynamicSite`3 , CodeContext , Object , MutableString )
11 at Microsoft.Scripting.Actions.DynamicSite`3.UpdateBindingAndInvoke(CodeContext context, T0 arg0, T1 arg1)
12 </dialogresult:0000002c></pre>
Some of you are probably wondering why the 2nd to last line worked but the last line doesn't. They are both static methods of imported libraries which take a single string argument. If someone has looked through the DLR scripting code and knows, post a comment. Thanks!
Additional resources (where some of this information came from):
- John Lam's Blog - The creator IronRuby
- Scott Gunthrie's Blog - Good example of using IronRuby with the new windows UI framework in .NET 3.0
Timeline
- Funny or Die in top 10 by PC World
- RailsConf day 2 - Presentations galore
- RailsConf day 1, the Swedish perspective...
- RailsConf Berlin Day -1
- ELCs Designer Toby Keller Featured
- IronRuby prealpha
- Swfchart Generator
- ELC Sponsors Bratwurst on Rails
- Ruby on Rails Enterprise - PC World
- Ruby on Rails, C# Use Increasing
- Ruby on Rails Keynote at RailsConf
Comments