Forum: IronRuby problem setting .NET member variables

Posted by Andrew Warner (andrewww)
on 2010-02-27 08:02
Hello, can anyone help me with this issue? I have the following code
running in C#:

ScriptRuntime runtime = Ruby.CreateRuntime();
ScriptEngine engine = Ruby.GetEngine(runtime);
ScriptScope scope = runtime.CreateScope();
scope.SetVariable("model", model);
StreamReader sr = new
StreamReader(ConfigurationManager.AppSettings["RubyFlagsPath"] +
flagName + ".rb");
string rubyScript = sr.ReadToEnd();
engine.Execute(rubyScript, scope);

which runs this Ruby code in part:

model.Transaction.Runs[0].RunLoan.RunBorrowers[2].RunLoan.RunFlagTestResults[0].Passed
= false
model.Transaction.Runs[0].RunLoan.RunBorrowers[3].RunLoan.RunFlagTestResults[0].Passed
= true

f.syswrite("passed3
#{model.Transaction.Runs[0].RunLoan.RunBorrowers[2].RunLoan.RunFlagTestResults[0].Passed}
\n")
f.syswrite("passed4
#{model.Transaction.Runs[0].RunLoan.RunBorrowers[3].RunLoan.RunFlagTestResults[0].Passed}
\n")

The output I get is the following:

true
true

Obviously something is not quite right, the results should have been
false, true. Now, I've tried this with up to four borrowers and each
time the consistent pattern I'm seeing is that whatever I set the last
passed status to is set for ALL the borrowers. Somehow Ruby is setting
the passed status for all borrowers at once with each call, even though
they are in completely different objects.
Posted by Andrew Warner (andrewww)
on 2010-03-01 17:19
I believe this was an internal object reference issue - in .NET, not in 
Ruby. thanks!
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.