faithfulgeek.org

Agile web development

Fun with Ruby.NET!

December 26th, 2007

I started really playing with the Gardens Point Ruby.NET compiler. I wrote a little script that shows the true coolness of Ruby.NET:


require 'mscorlib.dll'

#Using System.Console.WriteLine to print to the screen
System::Console.WriteLine "Hello World!" 

names = ['Joe', 'Katie', 'Bob', 'Sue', 'Ann']

names.each do |name| puts "Hello #{name}!" end

# Create a .NET ArrayList
list = System::Collections::ArrayList.new

# Add the Ruby array to the .NET ArrayList
list.AddRange names

# Iterate through ArrayList and print Hello, name to the screen using System.Console.WriteLine
0.upto list.Count-1 do |i|
  System::Console.WriteLine "Hello {0}!", list[i]
end

Enjoy!