Hi --

On Sat, 22 Mar 2008, Roger Pack wrote:

> Roger Pack wrote:
>
> # a class to match
>
> class Number
> def Number.matches? param
>   return true if param.class == Fixnum or param.class == Float or
> param.class == BigDecimal
> end
> end
>
>
> def verify_params params_to_verify
>  for param, should_match_this_class in params_to_verify do
>    if should_match_this_class.respond_to? :matches?
>      raise 'poor parameter' unless should_match_this_class.matches?
> param
>    else
>      raise 'poor parameter' unless param.class ==
> should_match_this_class
>    end
>  end
>
> end
>
> def method_1 a, b, c
> verify_params a => Number, b => String
>
> end
>
> Ahh. Type checking at last.

It's class checking actually, not type checking. Type is different
from class in Ruby.


David

-- 
Upcoming Rails training from David A. Black and Ruby Power and Light:
   ADVANCING WITH RAILS, April 14-17 2008, New York City
   CORE RAILS, June 24-27 2008, London (Skills Matter)
See http://www.rubypal.com for details. Berlin dates coming soon!