From: James Coglan Date: 2008-11-18T02:56:15+09:00 Subject: Re: How can I overload a method in Ruby ------=_Part_32661_19912487.1226944782108 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline 2008/11/17 Brian Adkins > pjb@informatimago.com (Pascal J. Bourguignon) writes: > > > Zhao Yi writes: > >> 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 > > > > Call it: buildWithDirectory(directory) > > build_with_directory would probably be a more conventional Ruby function > name. In this case, this would be more Ruby-idiomatic: def build(directory = nil) cd directory if directory make end ------=_Part_32661_19912487.1226944782108--