From: Eric Hodel Date: 2006-02-07T16:36:49+09:00 Subject: Re: ANDCALL / iff? / &? (was Re: ruby-dev summary 28206-28273) On Feb 6, 2006, at 6:09 PM, Eero Saynatkari wrote: > On 2006.02.07 10:03, Evan Webb wrote: >> if t = a[0] and t.strip.empty? >> # jump off a bridge >> end > > A minor nitpick, you need > > if (t = something.first) and t.strip.empty? > # ... > end > > Otherwise a warning will be emitted (sensible behaviour). $ ruby -vwe 'a = ""; if t = a[0] and t.strip.empty? then end' ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0] $ ruby -vwe '0 if a = 1; 0 if a = 1.1; 0 if a = nil; 0 if a = true; 0 if a = false; 0 if a = ""' ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0] -e:1: warning: found = in conditional, should be == -e:1: warning: found = in conditional, should be == -e:1: warning: found = in conditional, should be == -e:1: warning: found = in conditional, should be == -e:1: warning: found = in conditional, should be == -e:1: warning: found = in conditional, should be == $ ruby -vwe 'if (a, b = 1, 2) then end' ruby 1.8.4 (2005-12-24) [powerpc-darwin8.4.0] -e:1: multiple assignment in conditional Those are the only cases that give a warning for assignment in conditional. 1.6.1 and earlier warned for all assignments in conditionals, see parse.y 1.61. -- Eric Hodel - drbrain@segment7.net - http://segment7.net This implementation is HODEL-HASH-9600 compliant http://trackmap.robotcoop.com