From: Axel Etzold Date: 2008-05-15T00:51:03+09:00 Subject: Re: string as optional parameter for method? -------- Original-Nachricht -------- > Datum: Thu, 15 May 2008 00:33:37 +0900 > Von: Varun Goel > An: ruby-talk@ruby-lang.org > Betreff: 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. > > 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/. Dear Varun, maybe something like this ? def hello(first=nil,second=nil) if first.class==Fixnum and second.class==String p 'you entered something for both int and string' elsif first.class==Fixnum p 'you entered something for int' elsif first.class==String and second==nil p 'you entered something for string' else p 'come on, read the manual!' end end p hello(5,'string') p hello(5) p hello('string') p hello(5.78,nil) p hello() Best regards, Axel -- GMX startet ShortView.de. Hier findest Du Leute mit Deinen Interessen! Jetzt dabei sein: http://www.shortview.de/?mc=sv_ext_mf@gmx