Ruby
Ruby was originally created in 1993. Since then, it has maintained a small but active community of followers – growing rapidly after the introduction of the ‘Rails’ (or, Ruby on Rails) framework for rapid web development.
Microsoft have recently registered their interest in the language, by creating a version of Ruby for .NET - named IronRuby. As this project is built on top of the Dynamic Language Runtime (DLR) – currently, a work in progress – it is still in a very early stage of development. Nevertheless, Microsoft has released the source to the current implementation; currently described as a “pre-alpha” release.
Eventually, it is hoped that the complete .NET framework will be available - as well a large number of ruby-specific libraries; however, the majority of these frameworks are currently unimplemented.
Despite these obvious caveats, it is likely that Ruby’s significant mindshare may attract a great deal of attention once it is released.
In the following weeks, I intend to explore the current IronRuby implementation, and document my initial thoughts on its use in a .NET centric environment.
Getting started
At the moment, the best way to get IronRuby up and running, is to download the source code: here. Once you have downloaded and unzipped the project, open up the solution in VS. You may need to open VS first, and then select "file-open" to open the solution.
Once the solution is opened, set the build target to 'release', right click on the solution, and 'rebuild all'.
Once the solution has built, take a peak in the bin/release directory; you will see a couple of executables:
# rbx
This is an interactive ruby shell, similiar to 'irb' on other platforms.
# RubyTestHost
This runs a series of unit tests against IronRuby, to show the current level of implementation.
Double click rbx.exe to open the interactive IronRuby shell. The interactive shell is similar to the ‘immediate window’ in the VS debugger; it allows you to create and manipulate objects.
Simple Objects
You can easily create simple objects, by instantiating them dynamically:
For ie:
X = “Hello World!”
Simple arithmetic works as expected:
2 + 3
Or,
4 + x.length
Likewise, arrays are specified as:
A = [‘carrot’, ‘banana’, ‘apple’]
To print a string, use the ‘puts’ command:
Puts x
Simple Collections
Ruby treats everything as objects; therefore, to repeat a given function we can use the ‘times’ method of a standard integer:
X = “awesome”
5.times do puts x end
Likewise, we can use the ‘each’ method to enumerate collections – similar to the foreach keyword in C#
A.each do | e| puts e end
Simple .NET objects
A subset of the .NET framework is currently implemented; we can create and inspect a range of objects as follows:
.NET Example 1: Create a Simple messagebox
# import the required libraries
require 'mscorlib'
require 'System.Drawing'
require 'System.Windows.Forms'
# Create a simple message box
MessageBox = System::Windows::Forms::MessageBox
MessageBox.show('awesome')
.NET Example 2: Create a Simple form
# import the required libraries
require 'mscorlib'
require 'System.Drawing'
require 'System.Windows.Forms'
#create the form
form = System::Windows::Forms::Form
window = form.new
#set form properties, and show
window.show
window.text = 'awesome'
window.hide
Summary
Hopefully, you have seen how easy it is to get IronRuby up and running, tested a few simple language functions, and seen how simple it is to create simple .NET objects using the interactive IronRuby shell.