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.@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.fried...@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 <li...@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@rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
>
_______________________________________________
Ironruby-core mailing list
Ironruby-core@rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

Reply via email to