From: Eli Bendersky Date: 2006-03-27T02:28:53+09:00 Subject: Re: Verifying keyword arguments Joel VanderWerf wrote: > Ross Bamford wrote: > .. > > Not sure about libraries (though I'm sure they are out there, check RAA > > and Rubyforge) but here's a little trick I've used before: > > > > args = { :one => 'two', :three => 'four' } > > # => {:three=>"four", :one=>"two"} > > > > h = Hash.new { |h,k| raise ArgumentError, "#{k}" }.merge(args) > > # => {:three=>"four", :one=>"two"} > > > > h[:one] > > # => "two" > > > > h[:three] > > # => "four" > > > > h[:two] > > ArgumentError: two > > from (irb):5 > > from (irb):11 > > > > This way, you never actually check the arguments explicitly, but you'll > > be told if your method uses one that wasn't passed. Obviously for > > optional arguments you go to the original hash. > > > > What about using rescue for optional arguments? It might be slower though. > What do you mean ? Can you provide an example ?