From: gabriele renzi Date: 2003-11-18T22:32:22+09:00 Subject: Re: testing argument type and duck typing, newbie question il Tue, 18 Nov 2003 13:34:32 +0100, Raphael Bauduin ha scritto:: >Hi, > >I have a method taking one argument that can be an integer or a string. >How do I test the argument to know if it's a string or an integer? All >the duck typing things I've read make me wonder what's the best way >to determine if the argument is an integer or a string..... you don't want duck typing :) >> def f(a,b) >> raise 'wrong parameters!' unless a.is_a?String and b.is_a?Numeric >> end => nil >> f(1,2) RuntimeError: wrong parameters! from (irb):2:in `f' from (irb):4 >> f('yes',2) => nil >> or if you wont you can get StrongTyping and do: def f(a,b) expect(String,a,Integer,b) end