From: Neville Burnell Date: 2005-09-16T13:13:45+09:00 Subject: Re: "unless" keyword Oops, boolean logic breakdown ... !(a or b) = !a and !b, so errors.add(:price, "should be positive") if !price.nil? and price <= 0.0 -----Original Message----- From: Neville Burnell [mailto:Neville.Burnell@bmsoft.com.au] Sent: Friday, 16 September 2005 2:04 PM To: ruby-talk ML Subject: Re: "unless" keyword "Unless" == "if not" so errors.add(:price, "should be positive") unless price.nil? || price > 0.0 Is equivalent to errors.add(:price, "should be positive") if !price.nil? and price > 0.0 -----Original Message----- From: Mike Novecento [mailto:mike.novecento@gmail.com] Sent: Friday, 16 September 2005 1:42 PM To: ruby-talk ML Subject: "unless" keyword Ok guys, you convinced me: Ruby is the way to go. I have been reading online for a few hours now, and it looks simply fantastic (especially with Ruby on Rails). I am so excited, I have been programming for years, and never thought it could be so fun. I have a first question. Looking at some code online, I have seen this line of code from a the site of pragmatic programmer: errors.add(:price, "should be positive") unless price.nil? || price > 0.0 I understand that it is required to validate that a price is strictly positive. My question, maybe very easy, is... how does it exactly work? I thought it should be "ADD ERROR unless NOT NIL AND PRICE > 0.0"... why he uses (OR) ||? Maybe I am missing the logic of the keyword "unless". I feel dumb :-) Thanks in advance, Mike.