Search code examples
c#delegatesironrubyyield

Calling IronRuby from C# with a delegate


Is it possible to call an IronRuby method from C# with a delegate as parameter in such a way that yield would work?

The following gives me a wrong number of arguments (1 for 0) exception.

Action<string> action = Console.WriteLine;
var runtime = Ruby.CreateRuntime();
var engine = runtime.GetEngine("rb");
engine.Execute(@"
                 class YieldTest
                   def test
                     yield 'From IronRuby'
                   end
                 end
                ");
object test = engine.Runtime.Globals.GetVariable("YieldTest");
dynamic t = engine.Operations.CreateInstance(test);
t.test(action);

Solution

  • Got an answer by IronRuby core team member Tomáš Matoušek on the IronRuby-core list that it's not possible. Yet.