From: Justin Collins Date: 2006-10-30T17:52:28+09:00 Subject: Re: Using "not" in compound conditions Peter Lynch wrote: > Hi > I am still a beginner at Ruby, and have just arrived at this in my > learning curve. > > I would like to code > not(condition1) && not(condition2) > This is accepted in irb - > not(condition1) && condition2 > but this produces a syntax error > condition1 && not(condition2) > > I do not get it (obviously). I do not even know what to ask in reply - > How do I code a compound condition, without introducing extra wrappers > like - > (not(condition1)) && (not(condition2)) > > Regards > Peter > "&&", "||", and "!" have higher precedence than "and", "or" and "not" - so it can be tricky. However, you could do: (not condition1) && (not condition2) or, not mixing the two: not condition1 and not condition2 Of course, it's best to be clear, and parentheses help that. Hope that helps. -Justin