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

Tomas Matousek Tomas.Matousek at microsoft.com
Fri Feb 25 03:25:11 EST 2011

Wouldn't this work?

dynamic globalConstants = engine.Runtime.Globals



module MyModule
  class MyClass

Haven't tried. Let me know if it works.


From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Shay Friedman
Sent: Thursday, February 24, 2011 10:38 PM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Accessing a Module's Classes from C# with dynamic

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 = engine.ExecuteFile(@"c:\code\generator\lib\generator\generator_cmd_line.rb");

    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: http://twitter.com/ironshay

On Thu, Feb 24, 2011 at 4:41 PM, Rob R. <lists at ruby-forum.com<mailto: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();

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<mailto:Ironruby-core at rubyforge.org>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20110225/6ee60552/attachment.html>

More information about the Ironruby-core mailing list