From: Eric Mahurin Date: 2005-08-07T11:00:43+09:00 Subject: Re: polymorphism and/or named parameters: the ruby way? --- Stephan Mueller wrote: > 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 > > ... I was thinking something like this (I don't think the above does what you want): class MyClass def self.new_s(s) obj = new # do sth with s and obj obj end def self.new_i(i) obj = new # do sth with i and obj obj end end ____________________________________________________ Start your day with Yahoo! - make it your home page http://www.yahoo.com/r/hs