我试图弄清楚如何检索存储在 Person 类中的值。问题只是在我定义了 Person 类的实例之后,我不知道如何在 IronRuby 代码中检索它,因为实例名称在 .NET 部分中。
/*class Person
attr_accessor :name
def initialize(strname)
self.name=strname
end
end*/
//We start the DLR, in this case starting the Ruby version
ScriptEngine engine = IronRuby.Ruby.CreateEngine();
ScriptScope scope = engine.ExecuteFile("c:\\Users\\ron\\RubymineProjects\\untitled\\person.rb");
//We get the class type
object person = engine.Runtime.Globals.GetVariable("Person");
//We create an instance
object marcy = engine.Operations.CreateInstance(person, "marcy");