[Ironruby-core] Compare Patch

Peter Bacon Darwin bacondarwin at googlemail.com
Mon Nov 12 08:54:56 EST 2007


I have just realised that the overload I created in FixnumOps is nonsense,
sorry:

 

        [RubyMethod("<=>")]

        public static object Compare(int lhs, int rhs)

        {

            return Compare(lhs, (int)rhs);

        }

 

        [RubyMethod("<=>")]

        public static object Compare(int lhs, object rhs)

        {

            if (rhs is int)

            {

                return Compare(lhs, (int)rhs);

            }

            return null;

        }

 

Since there is already an overload that takes int rhs then the second
overload will never get called with an int.  Therefore the first three lines
of the method are never needed.  That leaves this method looking like:

 

        [RubyMethod("<=>")]

        public static object Compare(int lhs, object rhs)

        {

            return null;

        }

 

This then begs the question of is there a better way to pick up default
cases like this at binding time?

 

There is also a need for other overloads such as

 

        [RubyMethod("<=>")]

        public static int Compare(int lhs, double rhs)

        {

            return Convert.ToDouble(lhs).CompareTo(rhs);

        }

 

But again is there a more generic method of coercion for these types.  The
binder already attempts to do convert parameters but in this case the
conversion is the reverse (in effect converting the value of self rather
than rhs).

Other implementations talk about a coerce framework but this is offered due
to a lack of method overloading based on types in Ruby.  I assume that the
way the binding works actually encourages such overloads in IronRuby.

 

Again sorry if I am being dumb.

 

Pete

 


No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.503 / Virus Database: 269.15.29/1124 - Release Date: 11/11/2007
10:12



No virus found in this outgoing message.
Checked by AVG Free Edition. 
Version: 7.5.503 / Virus Database: 269.15.29/1124 - Release Date: 11/11/2007
10:12
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/ironruby-core/attachments/20071112/cfc9cc3d/attachment.html 


More information about the Ironruby-core mailing list