From: Gennady Bystritsky Date: 2008-05-15T00:44:05+09:00 Subject: Re: string as optional parameter for method? > -----Original Message----- > From: varun.rajeshkumar@gmail.com [mailto:varun.rajeshkumar@gmail.com] > Sent: Wednesday, May 14, 2008 8:34 AM > To: ruby-talk ML > Subject: string as optional parameter for method? > > Hi All, > I have one method like def hello(int,string) > Now i want that if user pass int value or string value then it should > search on the basis of one of those. So as far as I understand you want methods overloaded on the parameter type? Ruby does not support method overloading directly. One way you can do it is something like that: def hello(arg) case arg in when String then hello_with_string(arg) when Integer then hello_with_integer(arg) else raise "Unsupported parameter type" end end Ruby methods may have default parameters, however it may be not what you are after as this facility does not guarantee parameter types. Gennady. > > means i want both as optional parameter. > Please tell me how to do this in ROR. > Thanks > Varun > -- > Posted via http://www.ruby-forum.com/.