[Ironruby-core] Compare Patch

Peter Bacon Darwin bacondarwin at googlemail.com
Tue Nov 13 01:21:56 EST 2007


That would be interesting and very duck-like.  From looking at ruby doc it
appears that the Numeric class implements <=> such that it either returns 0
(if both sides are equal) or nil.  Pushing my method up to Numeric and
implementing it properly makes more sense.

Pete

 

-----Original Message-----
From: ironruby-core-bounces at rubyforge.org
[mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Tomas Matousek
Sent: 12 November 2007 22:46
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Compare Patch

 

For now, use overloads for method specialization on parameter type. 

We might do some implicit conversions (e.g. MutableString <-> CLR string) in
the binder but such conversions need to be general, not specific to any
operator/method.

I’m also thinking about adding support for “overloading by type and
protocol” (as opposed to type only). I.e. instead of this

 

public static void Foo(object obj) {

                if (RubySites.RespondsTo(obj, “bar”) { … 1 …} else if
(RubySites.RespondsTo(obj, “baz”) {… 2 …} else { … 3 …}

}

 

one would just write (declaratively):

 

public static void FooForBar([HasMethod(“bar”)]object obj) {

                … 1 …

}

 

public static void FooForBaz([HasMethod(“baz”)]object obj) {

                … 2 …

}

 

public static void Foo(object obj) {

                … 3 …

}

 

But it’s not a priority right now. We’ll see.

 

Tomas

 

From: ironruby-core-bounces at rubyforge.org
[mailto:ironruby-core-bounces at rubyforge.org] On Behalf Of Peter Bacon Darwin
Sent: Monday, November 12, 2007 5:55 AM
To: ironruby-core at rubyforge.org
Subject: Re: [Ironruby-core] Compare Patch

 

 

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?

 

 


No virus found in this incoming 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/20071113/01a2a735/attachment.html 


More information about the Ironruby-core mailing list