From: Zhao Yi Date: 2008-11-17T17:02:13+09:00 Subject: Re: How can I overload a method in Ruby Pe単a, Botp wrote: > From: Zhao Yi [mailto:youhaodeyi@gmail.com] > # ok I understand. Just curious, overload is a good feature in OO > # programming. Why doesn't Ruby support it? If I use the method you > # mentioned, I have to check the parameters and use if - else > # or swith to distinguish them. > > maybe because of the ff dilemma: > > def m(1) > end > > def m("one") > end > > > ruby will be forced to check type... wc leads to static typing... wc is > not matz ruby.. > > btw, Zhao, can you give us a real case where you really need to do > method loading? > > kind regards -botp I want to write a build method which will build source code in a directory. I assume there are two build methods, one doesn't have parameter while the other have one parameter. The method without parameter will build the source code in default directory, the method with one parameter will build the source code in the directory which is specified by this parameter. With method overloading, I can write them as below: def build() make end def build(directory) cd directory make end but without overloading, I have to do this: def build(directory) if(directory == nil) make else cd directory make endif end -- Posted via http://www.ruby-forum.com/.