0

It seems impossible to create an object using its default constructor when there is a static .New() method defined on the class:

.NET class:

public class Tester
{
    public static void New()
    {
        Console.WriteLine("In Tester.New()");
    }

    public Tester()
    {
        Console.WriteLine("In constructor");
    }
}

IronRuby code:

Tester.new
Tester.New

Both of these lines call Tester.New(), not the constuctor. It seems impossible to call the constructor of the Tester class.

Is there a workaround, or is this a bug?

Philippe Leybaert
  • 168,566
  • 31
  • 210
  • 223

1 Answers1

1

The first one is just an unavoidable ambiguity. If you want to make CLI classes look like Ruby classes, you have no choice but to map the constructor to a new method. So, if you have both a real new method and a synthesized one which maps to a constructor, whatever you do, either the synthetic method shadows the real one or the other way around. Either way, you lose.

That's why all CLI classes have a synthetic clr_new method:

Tester.clr_new
# In constructor
Jörg W Mittag
  • 363,080
  • 75
  • 446
  • 653