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

Charles Oliver Nutter charles.nutter at sun.com
Fri Sep 28 12:12:43 EDT 2007

Eric Nicholson wrote:
> 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 
> otherwise.

How can this work? In order for var to be available in the script, it 
would have to be added into the toplevel scope. This would either mean 
that var is now available in all toplevel scopes across the system 
(incompatible with Ruby) or that it would only be available in the 
current thread's scope above toplevel (which would prevent seeing it in 
other threads. I'm a little confused. In JRuby we opted to not allow 
external variable binding into the eventual execution scope, because it 
seemed to violate that the scope should be created fresh for each script 

- Charlie

More information about the Ironruby-core mailing list