Hey guys.

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:
module RbScriptApp
    class Foo
        def Bar()
            return (rand(100) + 1).to_s();
        end
    end
end



Initially, I thought it would be as easy as typing
dynamic globals = myRuntime.Globals;
dynamic myClass = globals.RbScriptApp.Foo.@new();
myClass.Bar();
...

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 EnumerateConstants and manual
lookup of the class name I want, but it doesn't have the syntactic
elegance of the dynamic keyword... Any thoughts?

Thanks.

-- 
Posted via http://www.ruby-forum.com/.
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to