Re.Mark

My Life As A Blog

Use .NET classes in IronRuby

leave a comment »

Having posted how to use .NET classes in IronPython, I thought I should repeat the exercise in IronRuby.  I figured I’d use the same assembly I built for the IronPython example.  To start IronRuby (which, again, I’m assuming you have already installed) type ir at a command prompt.  You should see something like this:

image

First thing is to require the SampleClasses assembly.  Here’s how:

>>>require ‘c:/lib/SampleClasses.dll’

and you should the following output:

=> true

Let’s import the namespace:

>>>include SampleClasses

and the output this time should be:

=> Object

Next, create an instance of the User class:

>>>a = User.new

which should lead to this reponse:

=> SampleClasses.User

Time to set a property:

>>>a.Name = ‘Bob’

and you’ll see that worked from the response:

=> “Bob”

Of course, you can check if you like:

>>>puts a.Name

which will duly report that our user is called Bob:

Bob
=> nil

It really is that easy.   Now you can go and have some fun with IronRuby and .NET assemblies.

Advertisements

Written by remark

June 4, 2009 at 5:11 pm

Posted in .NET, Ruby

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: