# Still plugging away at some simple IronRuby stuff

**URL:** <https://www.ruby-forum.com/t/still-plugging-away-at-some-simple-ironruby-stuff/127306>\
**Category:** IronRuby\
**Created:** [January 28, 2008, 2:30am UTC](https://www.ruby-forum.com/t/still-plugging-away-at-some-simple-ironruby-stuff/127306 "2008-01-28T02:30:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 2:30am UTC](https://www.ruby-forum.com/t/still-plugging-away-at-some-simple-ironruby-stuff/127306/1 "2008-01-28T02:30:33Z")

</div>

OK, I’m making progress… Though my wife just got home, so this might  
not last much longer 😉

I am following the example at  
[http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp](http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp)

NOTE: I tried to be helpful and update that page with the examples  
that were just posted to the list, but now the page includes this the  
IScriptModule().SetVariable code - which doesn’t appear to be valid  
anymore)

This is what I’m using instead and I get a MissingMethod error on  
widget. I’d try using this method (  
scriptenvironment.ExecuteSourceUnit(rubyengine.CreateScriptSourceFromString(script)  
); ) but CreateScriptSourceFromString doesn’t appear to have a  
signature for IScriptModule, or IScriptScope.

Thoughts?

```
       IScriptEnvironment scriptenvironment =

```

ScriptEnvironment.GetEnvironment();  
IScriptEngine rubyengine =  
scriptenvironment.GetEngine(“ruby”);

```
       string script = "puts 'Ruby and ' + widget.to_s + '

```

together at last’";  
IScriptScope scope = scriptenvironment.CreateScope();  
scope.SetVariable(“widget”, “.Net”);  
rubyengine.Execute(scope,  
rubyengine.CreateScriptSourceFromString(script));  
Console.ReadKey();

–  
Greg A.  
Software Development Manager  
SSI Services

[http://kc.vanadium.com](http://kc.vanadium.com)  
[http://www.pghcodingdojo.org](http://www.pghcodingdojo.org)  
[http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [January 28, 2008, 2:27pm UTC](https://www.ruby-forum.com/t/still-plugging-away-at-some-simple-ironruby-stuff/127306/2 "2008-01-28T14:27:48Z")

</div>

IScriptModule is now IScriptScope from what I understand. I couldn’t  
figure out how to create or access local or instance variables, but  
you can use a global.

I got this:

using System;  
using Ruby;  
using Ruby.Runtime;  
using Microsoft.Scripting;  
using Microsoft.Scripting.Hosting;  
namespace RubyExample  
{  
static class Program  
{  
///

#  
/// The main entry point for the application.  
///   
[STAThread]  
static void Main()  
{  
IScriptEngine rubyengine =  
IronRuby.GetEngine(IronRuby.CreateRuntime());  
IronRuby.GetExecutionContext(rubyengine.Runtime).GlobalVariables[SymbolTable.StringToId(“widget”)]  
= “.NET”;  
rubyengine.Execute(rubyengine.CreateScope(),  
rubyengine.CreateScriptSourceFromString(“puts ‘Ruby and ’ +  
$widget.to\_s + ’ together at last’”));

```
        Console.ReadKey();

    }
}

```

}

On Jan 27, 2008 8:30 PM, Greg A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> ```
> IScriptEngine rubyengine = scriptenvironment.GetEngine("ruby");
> 
> ```
> 
> removed\_email\_address@domain.invalid  
> [http://rubyforge.org/mailman/listinfo/ironruby-core](http://rubyforge.org/mailman/listinfo/ironruby-core)

–  
Michael L.  
[Polymath Programmer]  
[http://michaeldotnet.blogspot.com](http://michaeldotnet.blogspot.com)

---

<div class="post-metadata">

**Author:** ![akinsgre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/ce73a5/32.png) [@akinsgre](https://www.ruby-forum.com/u/akinsgre)\
**Post date:** [February 3, 2008, 11:12pm UTC](https://www.ruby-forum.com/t/still-plugging-away-at-some-simple-ironruby-stuff/127306/3 "2008-02-03T23:12:37Z")

</div>

On Jan 27, 2008 8:30 PM, Greg A. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> I am following the example at  
> [http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp](http://ironruby.rubyforge.org/wiki/wiki.pl?ExecutingIronRubyFromCSharp)
> 
> NOTE: I tried to be helpful and update that page with the examples  
> that were just posted to the list, but now the page includes this the  
> IScriptModule().SetVariable code - which doesn’t appear to be valid  
> anymore)

FYI, I just updated this page to fix the problem I caused last weekend.

–  
Greg A.  
Software Development Manager  
SSI Services

[http://kc.vanadium.com](http://kc.vanadium.com)  
[http://www.pghcodingdojo.org](http://www.pghcodingdojo.org)  
[http://www.insomnia-consulting.org/monologue](http://www.insomnia-consulting.org/monologue)
