Roger Pack wrote:
> My personal ruby wish-list (for any feedback):

I guess it's been suggested here before, but I have often wished for a 
way to have 'tighter' control over the variables passed to a parameter. 
Sometimes duck typing doesn't immediately catch errors, until you run 
through certain (possibly rare sequences).  So anyway my wish is for 
checking of parameters.  Fortunately it seems already possible (as about 
30% of rush wishes seem :P )



# 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.
Ok you may begin to throw the stones :)
I actually like this setup since it helps describe the parameters.
Thanks :)

-R
-- 
Posted via http://www.ruby-forum.com/.