# Compiling Ruby classes to assemblies for use with Unity3D (which uses Mono 1.2.4)

**URL:** <https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590>\
**Category:** IronRuby\
**Created:** [December 22, 2009, 12:25pm UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590 "2009-12-22T12:25:08Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 22, 2009, 12:25pm UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590/1 "2009-12-22T12:25:08Z")

</div>

Hi,

I want to be able to use Ruby code in the Unity3D game engine, which  
embeds GNU Mono 1.2.4 to provide support for various languages (a  
ECMAScript-based language, Boo, and C# - they don’t upgrade the  
ancient Mono version to keep compatibility with games designed for  
older versions of Unity3D).

Forgive my use of terminology, I’m new to this .NET/Mono malarky 🙂

I was told that I can product .NET 2 assemblies, plug them into  
Unity3D, and the classes will be accessible from the other languages.

Will I be able to use IronRuby to create .NET 2 assemblies in this  
manner?

Sorry for asking here, but the Unity3D people don’t seem interested in  
Ruby as much, and I just can’t live without coding in BDD style in a  
robust environment.

Thanks. Regards,  
Asfand

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 22, 2009, 1:27pm UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590/2 "2009-12-22T13:27:11Z")

</div>

You can’t compile to an assembly with IronRuby at this point. But you  
can  
reference the ironruby interpreter library and host the ruby engine in  
your  
application to have it execute ruby files.

[http://ironruby.net/Documentation/.NET/Hosting](http://ironruby.net/Documentation/.NET/Hosting)

But I don’t think that will completely solve your issue though because  
to  
interop with CLR classes their definitions must exist in the CLR so you  
would probably have to build some bridges.

the most straightforward way to do that is by defining CLR interfaces  
and  
adding them to IronRuby classes.

public interface IRobot{  
DeathAndDestructionMode ForgetAboutThe3Laws();  
}

in Ruby:

require ‘/path/to/interfaces/assembly’

class EvilBot  
include IRobot

def forget\_about\_the\_3\_laws  
DeathAndDestructionMode.world\_domination  
end  
end

a consuming C# class could then get an object you created with your  
hosting  
code and still talk to it because of the CLR interface.

If you’re after testing then you can use ruby tools like bacon/rspec to  
test  
your C# code. The only thing that will be weird if you’re going to use  
it  
this way is that ruby mockers have no clue what to do with CLR objects.  
I  
created a project that:

a) accepts patches and contributions  
b) gives you mocking that knows about the CLR

> **[GitHub - casualjim/caricature: IronRuby mocking library](https://github.com/casualjim/caricature)**
>
> IronRuby mocking library. Contribute to casualjim/caricature development by creating an account on GitHub.

* * *

Met vriendelijke groeten - Best regards - Salutations  
Ivan Porto C.  
Blog: [http://flanders.co.nz](http://flanders.co.nz)  
Google Wave: removed\_email\_address@domain.invalid  
Twitter: [http://twitter.com/casualjim](http://twitter.com/casualjim)  
Author of IronRuby in Action ([http://manning.com/carrero](http://manning.com/carrero))

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 22, 2009, 1:36pm UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590/3 "2009-12-22T13:36:33Z")

</div>

Hey,

On 12/22/09, Asfand Yar Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I want to be able to use Ruby code in the Unity3D game engine, which  
> embeds GNU Mono 1.2.4 to provide support for various languages (a  
> ECMAScript-based language, Boo, and C# - they don’t upgrade the  
> ancient Mono version to keep compatibility with games designed for  
> older versions of Unity3D).

Mono 1.2.4 is most probably too old to support IronRuby and the DLR.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [December 22, 2009, 2:32pm UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590/4 "2009-12-22T14:32:44Z")

</div>

2009/12/22 Jb Evain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> Hey,
> 
> On 12/22/09, Asfand Yar Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > I want to be able to use Ruby code in the Unity3D game engine, which  
> > embeds GNU Mono 1.2.4 to provide support for various languages (a  
> > ECMAScript-based language, Boo, and C# - they don’t upgrade the  
> > ancient Mono version to keep compatibility with games designed for  
> > older versions of Unity3D).
> 
> Mono 1.2.4 is most probably too old to support IronRuby and the DLR.

Thanks for that, I can now stop chasing a pointless dream 🙂

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 21, 2011, 10:40pm UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590/5 "2011-03-21T22:40:44Z")

</div>

Asfand yar Qazi wrote in post #875250:

> 2009/12/22 Jb Evain [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > Hey,
> > 
> > On 12/22/09, Asfand Yar Q. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> > 
> > > I want to be able to use Ruby code in the Unity3D game engine, which  
> > > embeds GNU Mono 1.2.4 to provide support for various languages (a  
> > > ECMAScript-based language, Boo, and C# - they don’t upgrade the  
> > > ancient Mono version to keep compatibility with games designed for  
> > > older versions of Unity3D).
> > 
> > Mono 1.2.4 is most probably too old to support IronRuby and the DLR.
> 
> Thanks for that, I can now stop chasing a pointless dream 🙂

Well, a long time has passed since I asked the previous question.  
Unity3D now uses GNU Mono 2.6, and I hope IronRuby has made progress  
too.

Is it now possible to compile Ruby files into assemblies to use with  
Unity3D’s Mono 2.6?

Thank you for your help. Regards,  
Asfand

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 22, 2011, 2:37am UTC](https://www.ruby-forum.com/t/compiling-ruby-classes-to-assemblies-for-use-with-unity3d-which-uses-mono-1-2-4/180590/6 "2011-03-22T02:37:24Z")

</div>

We are already targeting Mono 2.10. You can try building with msbuild on  
Windows using /p:Configuration=v2Debug and using the resulting binaries  
on Mono 2.6.  
Mono fixed a bunch of bugs since 2.6 though so it might not quite work.

Tomas
