From: Rick DeNatale Date: 2008-07-29T08:01:30+09:00 Subject: Re: "or" and "and" ------=_Part_32918_22923246.1217286118304 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline On Mon, Jul 28, 2008 at 7:04 AM, Alex Gutteridge wrote: > On 28 Jul 2008, at 11:39, es_ wrote: > > class Array >> >> def n ; self.size ; end >> >> def stem_and_leaf(st = 1) >> # if st != (2 or 5 or 10) then ; st = 1 ; end >> > > > This won't fly (as you've noticed). And as for WHY it doesn't fly. The expression 2 or 5 or 10 evaluates to 2 since anything but nil or false is 'truthy' in ruby and or returns its left hand operand it it's truthy otherwise it returns the evaluation of its right hand operand. So if st !=(2 or 5 or 10) then; st = 1;end might as well be if st != 2 then; st = 1;end -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ ------=_Part_32918_22923246.1217286118304--