On 3 Sep 2009, at 05:04, Nick Green wrote:
> More or less all my functions look something like
>
> def foo bar baz quux
>   if not bar.is_a? String or
>      not baz.is_a? FunkyDinosaur or
>      not quux.respond_to? "getEatenByFunkyDinosaur"
>      #complain about errors w/ raise or app specific complain function
>   end
>   # do some stuff
> end
>
>
> There has got to be a better way to go about this parameter checking
> business, but googling is not working (bad search terms maybe).  Is
> there?
>
> And I don't really mean other ways of writing the same logic, i.e.
>
> 3 statements that look like:
>
> complain "baz is no dinosaur!" unless baz.is_a? FunkyDinosaur
>
> does not seem a whole lot better to me than the above example

You're looking at the problem inside-out which is why you're finding  
yourself in such a tangle: in Ruby explicit type checking is very rare  
and in cases where you think you need it you're generally wrong and  
fighting against the language rather than flowing with it. Google the  
term "Duck Typing" and you should find lots of helpful advice on how  
to write your code in an idiomatic manner whilst still covering your  
arse against the kind of type errors which can occur using Exception  
handling.


Ellie

Eleanor McHugh
Games With Brains
http://slides.games-with-brains.net
----
raise ArgumentError unless @reality.responds_to? :reason