[Ironruby-core] Passing a .NET object to the RubyEngine...
enicholson at gmail.com
Fri Sep 28 13:28:43 EDT 2007
Someone at MS can probably answer this better than I, but I'm guessing that
passing in the module explicitly to the ExecuteCommand statement is what
makes this work. If you leave off that optional parameter the variable
isn't directly accessible.
You can always create a new module fairly easily and pass that in as well if
On 9/28/07, Charles Oliver Nutter <charles.nutter at sun.com> wrote:
> Eric Nicholson wrote:
> > Here's a quick example:
> > RubyEngine re = RubyEngine.CurrentEngine;
> > IScriptModule mod =
> > 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
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Ironruby-core