From: "Ara.T.Howard" Date: 2004-02-20T20:20:51+09:00 Subject: Re: proposal: let kind_of take more arguments On Thu, 19 Feb 2004, Simon Strandgaard wrote: > Date: Thu, 19 Feb 2004 16:29:42 +0100 > From: Simon Strandgaard > Newsgroups: comp.lang.ruby > Subject: Re: proposal: let kind_of take more arguments > > On Thu, 19 Feb 2004 08:19:33 -0700, Ara.T.Howard wrote: > > > > what do you reccomend (when a case won't do) ? > > > > ... > > unless choice.kind_of?(Zero) or choice.kind_of?(One) > > ... > > > > My brain is terrible at dealing with 'unless'. > If its just "unless something" then its ok. > But when its "unless a or b and c" then it chokes. > > Am I the only one feeling like this? > > Where can I seek help ? ;-) a digital logic book, the simplest, will help. de morgan's laws..., eg. noting that 'unless' is the negation of 'if', in otherwords 'unless' => 'if not' let ^ => and v => or ~ => negation Z => kind_of? Zero O => kind_of? One then we can say your original statement choice.kind_of?(Zero) == false and choice.kind_of?(One) == false as simply ~Z ^ ~O if we want use this conjunction in the negative sense (convert to 'unless') we can convert using the following heuristic 'negate each clause and flip the operation' so ~(~Z ^ ~O) => Z v 0 or choice.kind_of?(Zero) or choice.kind_of?(One) now we have the _negation_ of the conjuction. this is want we want though since were are trying to use it in the negative sense (unless). eg. we're done: unless choice.kind_of?(Zero) or choice.kind_of?(One) ... end if you express in simple terms it's pretty easy. eg. HTH. -a -- =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | URL :: http://www.ngdc.noaa.gov/stp/ | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done ===============================================================================