[Ironruby-core] Getting variable form IronRuby

Shay Friedman shay.friedman at gmail.com
Fri Aug 3 06:31:07 UTC 2012


Why not use the ModuleClass directly from C#?

For example, if your ruby file looks like that:

class ModuleClass  def getObjectHash(hashString)    return
hashString.to_s.to_clr_string  endend

Then in C# you'll use it as follows:

var engine = IronRuby.Ruby.CreateEngine();			var scope =
engine.ExecuteFile("module_class.rb");
 dynamic globals = scope.Engine.Runtime.Globals;dynamic module =
globals.ModuleClass. at new();string s = module.getObjectHash("yo
yo");Console.WriteLine(s ?? "NULL");


Shay.
--------------------------------------------------------
Shay Friedman |  CodeValue <http://codevalue.net/> Co-Founder, Dynamic
Languages and Web Technologies Expert | Microsoft Visual C# MVP | Author of
IronRuby Unleashed
Email: shay.friedman at gmail.com | Blog:
http://IronShay.com<http://ironshay.com/> |
Twitter: http://twitter.com/ironshay




On Fri, Jul 27, 2012 at 9:51 PM, Alexander Ranger <lists at ruby-forum.com>wrote:

> Thanks for your answer, Eduardo.
>
> I've done it as you adviced:
>
> hashString = ModuleClass.GetObjectHash(testObject).to_s.to_clr_string
> # in IronRuby code
>
> and tried to call it in C#:
>
> string netString;
> engine.ExecuteFile(path).TryGetVariable("hashString", out netString);
> Console.WriteLine(netString);
>
> Well, there are no mistakes in compiling Ruby code, but the netString is
> null after executing the ruby file.
>
> I guess that the hashString after executing just seems to be empty. Is
> it something wrong with calling it in C# or is it just expected to be
> so?
>
> --
> 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/20120803/61669577/attachment.html>


More information about the Ironruby-core mailing list