0

How can I call a generic method (.NET 3.5 SP1) from IronRuby v0.9? Trying to do something as obj.method(:method_name).of(String).call seems not to work as "of" is an unknown method.

Thanks a lot

JPW
  • 1,201
  • 11
  • 13

2 Answers2

2

You can also use array indexers to pass generic arguments to methods, and you can execute a proc with array indexers as well, so Shay's example can look like this too:

obj.method(:test)[String]["test"]
Jimmy Schementi
  • 1,239
  • 8
  • 17
  • This doesn't work for me Jimmy. obj.method(:test)[String] returns a String object - 'String', so passing ["test"] to it results in an exception. – Shay Friedman Oct 08 '09 at 08:27
1

It works for me (I'm using 0.9.1):

IronRuby:

obj = ClassLibrary1::Class1.new
obj.method(:test).of(String).call("test")

C#:

namespace ClassLibrary1
{
    public class Class1
    {
        public string Test<T>(T param)
        {
            return param.ToString();
        }
    }
}
Shay Friedman
  • 4,808
  • 5
  • 35
  • 51
  • You're right, this seems to be an issue with the v0.9 release (http://dlr.codeplex.com/Release/ProjectReleases.aspx?ReleaseId=20378). If I compile the 0.9.1 release myself, it works for me as well. – JPW Oct 06 '09 at 11:20
  • The 0.9.1 binary release is out now, so you don't need to compile it yourself – Jimmy Schementi Oct 08 '09 at 07:28