[Ironruby-core] Passing a .NET object to the RubyEngine...

Phil Haack haacked at gmail.com
Fri Sep 28 13:36:02 EDT 2007

Nice! I'll update the wiki. This worked for me.


From: ironruby-core-bounces at rubyforge.org
[mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Eric Nicholson
Sent: Friday, September 28, 2007 6:38 AM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Passing a .NET object to the RubyEngine...


Here's a quick example:

RubyEngine re = RubyEngine.CurrentEngine;
IScriptModule mod = ScriptDomainManager.CurrentManager.Host.DefaultModule

  string script = "puts 'Ruby and ' + var.to_s + ' together at last'"

 mod.SetVariable("var", ".NET")

  re.ExecuteCommand(script, mod);

A couple things to note:
1. var.to_s is necessary because I don't think IR is coercing CLR Strings to
Ruby Strings yet. 
2. I'm not sure why you need to pass in the default module to
ExecuteCommand, but I wasn't able to evaluate the variable in Ruby


On 9/28/07, Phil Haack <haacked at gmail.com> wrote:

Hi All, I posted some code for calling IronRuby code I found in the mailing
list onto the wiki.




  RubyEngine re = RubyEngine.CurrentEngine;

  string script = "s = 'let us get started'" + Environment.NewLine

    + "i = s.length");



The only thing is, I don't know how to pass a .NET object to the context of
the RubyEngine so it can be called from within the script. I'd like to
update the example with that.


Any help?



Ironruby-core mailing list
Ironruby-core at rubyforge.org


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20070928/21ad9bf9/attachment.html 

More information about the Ironruby-core mailing list