On Fri, Sep 27, 2002 at 05:16:38AM +0900, bbense+comp.lang.ruby.Sep.26.02 / telemark.stanford.edu wrote: > - - As I stated in a previous post this method overloading is > nothing but strict type checking in disguise. IHMO, one > of the whole points of ruby is to get beyond the limitations > of type checking and start to think in different and more > powerful ways. You lose much of the inherent power of > objects when you tie them down with type checking. It is IMHO just syntactic sugar (syntactic polymorphism): def do_foo(String b) def do_foo_str(b) ... ... end end def do_foo(Array c) def do_foo_arr(b) ... ... end end do_foo [1, 2, 3, "a", "b", "c"] do_foo_arr [1,2,3,"a","b","c"] do_foo "Hello" do_foo_str "Hello" Of course, we want to discriminate on the basis of the supported methods and not depending on the types. As Ruby is dynamically typed we tend to think that the type of an object is the set of methods it responds to, which is why classes don't really work w/ this kind of overloading. One foolish way I can think of would be the following: def do_foo<sort,bar>(b) # used when b can respond to sort and bar end def do_foo<each>(b) # when it has method each end There's a lot of reasons why it wouldn't work. And it's all sugar, anyway. -- _ _ | |__ __ _| |_ ___ _ __ ___ __ _ _ __ | '_ \ / _` | __/ __| '_ ` _ \ / _` | '_ \ | |_) | (_| | |_\__ \ | | | | | (_| | | | | |_.__/ \__,_|\__|___/_| |_| |_|\__,_|_| |_| Running Debian GNU/Linux Sid (unstable) batsman dot geo at yahoo dot com You will not censor me through bug terrorism. -- James Troup