From: Reyn Vlietstra Date: 2005-08-07T11:24:20+09:00 Subject: Re: polymorphism and/or named parameters: the ruby way? Comming from a C++ background I was also facing the same issue with methods, not initialize specifically. I found myself creating methods like: * delete_object_by_class(someclass) * delete_object_by_class_name(classname) * delete_object_by_name(name) * etc. The people on #ruby-lang helped me understand closures a bit better. So now instead of doing: delete_object_by_class(someclass) I do, delete_object{|o| o.class == someClass} By passing the test condition to the method through a block I cut out quite alot of bad looking code. On 8/7/05, Eric Mahurin wrote: > --- 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 > > > -- Reyn Vlietstra