From: Eleanor McHugh Date: 2008-05-29T00:24:00+09:00 Subject: Re: The duck's backside On 28 May 2008, at 14:15, Tobias Weber wrote: > In article > <9560F017-58CA-48EB-BCC3-3B16758516C1@games-with-brains.com>, > Eleanor McHugh wrote: > >>> uaid = "ignore" > > Ups, shoulda been c = Which makes things simpler ;) doit a, b, c = nil raise ArgumentError, "needs exactly one additional argument" if b && c v = b || c raise ArgumentError, "need a numeric parameter" unless v.respond_to? (:to_int) @post "first=#{a}&" + (b.nil? ? "second=ignored&third=#{v}" : "second=#{v}&third=ignored") end > So that doit() is only passed legal values? That should be the case, > but > I want to make extra sure not to give that foreign web service > something > it can't swallow. > >> def doit a, v, param = :second >> raise ArgumentError, "needs a numeric value" unless v.respond_to? >> (:to_int) >> v = "ignore" if (param == :third) && v > 0 > > That is essentially overloading doit() for first or second parameter, > and a good idea! So far I just wrapped the http calls in convenience > methods one by one. I'm not suggesting it's a good idea... Ellie Eleanor McHugh Games With Brains http://slides.games-with-brains.net ---- raise ArgumentError unless @reality.responds_to? :reason