From: Stephan Mueller Date: 2005-08-07T04:41:08+09:00 Subject: Re: polymorphism and/or named parameters: the ruby way? Hi Eric, * Eric Mahurin [050806 20:25]: > What you are talking about is really method overloading not > polymorphism in my opinion. Yes, I agree. :) > My take on the "ruby way" is to not overload methods by type > like you can easily do in java. Instead you just make multiple > distinct methods with each method taking its own "type". This > give maximal flexibility with duck-typing. > > There is no reason you can't make multiple new type class > methods that call the normal "new" method - you wouldn't need > an initialize in that case. Something like this? class MyClass def new_s(str) me = super # do sth with str return me end def new_i(int) me = super # do sth with int return me end ... > The closest you can come to named parameters is by using a hash > (right now, at least): > > def test(hash) > if hash[:p1] > ... > elsif hash[:p2] > ... > end > end > > test(:p1=>500) Okay, looks quite good for me. Not much more effort than real named params. Thanks! Steph.