[Ironruby-core] Getting variable form IronRuby

Alexander Ranger lists at ruby-forum.com
Thu Jul 26 06:13:07 UTC 2012


I'm using IronRuby 1.1.3 and .Net 4.

In IronRuby I've got two files:
1) Module.rb
# This file contains a class with static method GetObjectHash. The idea
is to parse the object find all it's properties and make a hash like:
{property_name => [property_type, property_value], ...}

2) Main.rb
# This file creates several objects from different classes and calls
GetObjectHash method.

Then I try to execute Main.rb using C#:

string path = "../../RubyTest.rb";
var runtime = IronRuby.Ruby.CreateRuntime();
var engine = runtime.GetEngine("rb");
engine.ExecuteFile(path);

Ok, it executes. And if in Main.rb I write the last command as

hashString = ModuleClass.GetObjectHash(testObject).to_s
print hashString

it prints into the console the hash I want to see. But. I'd like not to
use the last "print" command, and get the hashString variable into C#
where I can use it as normal string.

I tried to do that like:

dynamic netString;
engine.ExecuteFile(path).TryGetVariable("hashString", out netString);
string hash = netString as String;
Console.WriteLine(hash);

But hashString remained null. (Variable name is ok, I checked it).

Am I doing something wrong? How can I get "hashString" with stored data
into C#?

-- 
Posted via http://www.ruby-forum.com/.


More information about the Ironruby-core mailing list