[Ironruby-core] Accessing a Module's Classes from C# with dynamic

Shay Friedman shay.friedman at gmail.com
Fri Feb 25 01:38:11 EST 2011

I got it working using a kind of a hack/workaround.

I know this is kind of a hack/workaround, but I managed to do it this way:

I added the next code to the end of the ruby file:

    def hack(s)

And then used it from the C# code to get the class object:

    var engine = Ruby.CreateEngine();

    var scope =

    var genCmdLineObj = engine.Execute(String.Format("hack('{0}::{1}')",
"Generator", "CmdLine"), scope);

    var cmdLineObj = engine.Operations.CreateInstance(genCmdLineObj);
    var results = engine.Operations.InvokeMember(cmdLineObj, "run");
    return Content(results);

Kind of a hack, but hey, it works! :)

Shay Friedman |  Co-Founder @ CodeValue <http://codevalue.net/> |
C#/IronRuby MVP | Author of IronRuby Unleashed
Blog: http://IronShay.com <http://ironshay.com/> | Twitter:

On Thu, Feb 24, 2011 at 4:41 PM, Rob R. <lists at ruby-forum.com> wrote:

> to add directories to your search path from within C# you can do
> something like this:
> var engine  = Ruby.CreateEngine();
> var searchPaths = engine.GetSearchPaths().ToList();
> searchPaths.Add(@"c:\code\generator\lib");
> searchPaths.Add(@"C:\Ruby-ri-192\lib\ruby\1.9.1");
> engine.SetSearchPaths(searchPaths);
> Let me know if you find out how to access classes that are within
> modules from C#.  I'm having no luck.
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20110225/31c3952c/attachment-0001.html>

More information about the Ironruby-core mailing list