# Compiling .rb files vs. embedding and hosting?

**URL:** <https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323>\
**Category:** IronRuby\
**Created:** [January 9, 2009, 12:17pm UTC](https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323 "2009-01-09T12:17:20Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 9, 2009, 12:17pm UTC](https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323/1 "2009-01-09T12:17:20Z")

</div>

Hello,  
I’m starting to integrate IronRuby files into a VisualStudio C# project,  
mainly to write easy-to-maintain GUI builders.

As I don’t want to have .rb files lying around this deployment, I had  
that  
idea about embedding all the files inside an assembly, loading them at  
run  
time through resource manager and passing them to the IronRuby host I  
would  
start from C#.

While that would work, it would be even simplier to have these .rb files  
compiled to some assembly.

Is there a trick to compile a bunch of .rb files to an assembly today ?

thanks!

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 9, 2009, 9:45pm UTC](https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323/2 "2009-01-09T21:45:04Z")

</div>

Hi Jimmy,

thanks for the feedback (and the outlook snippet :-)!

I’ll try that.

cheers

– Thibaut

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 9, 2009, 10:30pm UTC](https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323/3 "2009-01-09T22:30:59Z")

</div>

The last 4 lines of the snippet could be slightly simplified:

var engine = IronRuby.Ruby.CreateEngine();  
engine.Execute(code);

Tomas

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 9, 2009, 9:08pm UTC](https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323/4 "2009-01-09T21:08:35Z")

</div>

Embedding the files as resources would be your best bet, as we don’t  
have compilation to an assembly working today.

Basically (compiled with outlook …):

var assembly = Assembly.GetExecutingAssembly();  
var textStreamReader = new  
StreamReader(assembly.GetManifestResourceStream(“foo.rb”));  
var code = textStreamReader.ReadToEnd();  
textStreamReader.Close();

var runtime = new ScriptRuntime();  
var ruby = IronRuby.Ruby.GetEngine(runtime);  
var source = ruby.CreateScriptSourceFromString(code);  
var result = source.Execute();

Compilation is something we want to support though.

~js

---

<div class="post-metadata">

**Author:** ![thbar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/eb8c5e/32.png) [@thbar](https://www.ruby-forum.com/u/thbar)\
**Post date:** [January 30, 2009, 9:14am UTC](https://www.ruby-forum.com/t/compiling-rb-files-vs-embedding-and-hosting/157323/5 "2009-01-30T09:14:05Z")

</div>

Hi,

just some words of feedback: it works perfectly 🙂

I’m beginning to start using an embedded IronRuby engine to create my  
windows forms programmatically inside a C# application, rather than  
from the designer.

thanks, I’ll keep you guys posted on my findings!

Thibaut

On Fri, Jan 9, 2009 at 10:30 PM, Tomas M.
