[Ironruby-core] Calling constructor when static .New() method is defined

Philippe Leybaert philippe at activa.be
Tue Jun 29 14:30:47 EDT 2010


Thanks, that does seem to work.

But I personally think this behavior is completely wrong. Calling .new from IronRuby should always call the constructor, not a static method named .New() that happens to exist somewhere in the class hierarchy. (if the .New() method is defined in a base class, you get the same problem).


Philippe

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek
Sent: dinsdag 29 juni 2010 19:24
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Calling constructor when static .New() method is defined

You can call CLR constructor using "clr_new" method:

Tester.clr_new

Tomas

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org [mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Philippe Leybaert
Sent: Tuesday, June 29, 2010 9:57 AM
To: ironruby-core at rubyforge.org
Subject: [Ironruby-core] Calling constructor when static .New() method is defined

Shay Friedman suggested I'd post this to the mailing list, as it may be a bug in IronRuby:

It seems impossible to call a constructor when there is a static .New() method defined on a class.

This is a minimal test case demonstrating the problem:

.NET (C#) 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

The ruby code above calls Tester.New() in both cases. There seems to be no way to call the regular constructor of this class.

_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core

_______________________________________________
Ironruby-core mailing list
Ironruby-core at rubyforge.org
http://rubyforge.org/mailman/listinfo/ironruby-core


More information about the Ironruby-core mailing list