How do I pass an ExpandoObject from C# into IronRuby?
Executing the below code gives me the following exception on the last line:
Invali开发者_运维知识库dOperationException: "unbound variable: value"
var rubyRuntime = Ruby.CreateRuntime();
rubyRuntime.UseFile("HandleMoveRequested.rb");
var engine = rubyRuntime.GetEngine("rb");
dynamic ruby = engine.Runtime.Globals;
var handler = ruby.HandleMoveRequested.@new();
dynamic msg = new ExpandoObject();
msg.x = 1;
msg.y = 2;
handler.handle(msg);
The contents of HandleMoveRequested.rb are:
class HandleMoveRequested
def handle(msg)
System::Console.WriteLine msg.x
System::Console.WriteLine msg.y
end
end
Basically I just want to be able to pass a fully dynamic object into that Ruby object's "handle" method and have it be able to access the "x" and "y" properties on that object. Am I barking up the wrong tree?
I tested your code (as-is) after building the latest from source: http://github.com/ironruby/ironruby
Please try this. I'd imagine the fix will be included in the next RC Build (RC3?) and later.
When you build from source, make sure you build the "V4 Release" build using Ruby4.sln
Edit: Tested myself, this works without issue in latest
精彩评论