string as optional parameter for method?

V

Varun Goel

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
 
A

Axel Etzold

-------- Original-Nachricht --------
Datum: Thu, 15 May 2008 00:33:37 +0900
Von: Varun Goel <[email protected]>
An: (e-mail address removed)
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

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,189
Latest member
CryptoTaxSoftware

Latest Threads

Top