I am currently experimenting with IronRuby as an extensibility solution
for my application. However, I have hit a roadblock. What I would like
to do is call Runtime.UseFile(“script.rb”), then access a global module
in the script, and instantiate a specific class in that module.
Here is the script file for reference:
return (rand(100) + 1).to_s();
Initially, I thought it would be as easy as typing
dynamic globals = myRuntime.Globals;
dynamic myClass = globals.RbScriptApp.Foo.@new();
but I soon found out this was not the case, as the builtin RubyModule
class does not support this dynamic syntax. Is there a way around this
or is it just plain impossible? I was unable to find any information
about how to do this (not even about RubyModule itself!) through Google.
The exception in question is a RuntimeBinderException:
‘IronRuby.Builtins.RubyModule’ does not contain a definition for ‘Foo’
Right now my workaround is a call to RubyModule.EnumerateConstants and
manual lookup of the class name I want, but it doesn’t have the
syntactic elegance of the dynamic keyword… Any thoughts?
EDIT: Just thought I’d add, I’d like to stay away from Engine.Execute()
if at all possible, unless someone can give me a reasonable case for not