Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Robert Klemme Newsgroups: comp.lang.ruby Subject: Re: How undefined values are handled with 'if' modifier. Date: Sat, 08 Dec 2012 10:34:09 +0100 Lines: 18 Message-ID: References: <7a182ec4-9f34-490b-9ac1-30f49f904b06@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net oskhfH2QMlPYPXl+ENyfPQ0hxAzxAdjtHP/Xl0UPLMX2jC/Tme7fw4sEULXcOEbbw= Cancel-Lock: sha1:zGIs1fI3E0hfo7a4azubKc4wo1w= User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/17.0 Thunderbird/17.0 In-Reply-To: <7a182ec4-9f34-490b-9ac1-30f49f904b06@googlegroups.com> Xref: csiph.com comp.lang.ruby:6692 On 12/07/2012 07:02 PM, michael.j.cannon@gmail.com wrote: > Why do these two expressions give different results when foo is undefined? > > foo if (foo = 3) # => NameError: undefined local variable or method `foo' for main:Object > if (foo = 3); foo end # => 3 > > Granted, an operator like ||= does something handy, even though it's inconsistent with foo = foo || 3 > but the if-expression-vs-modifier inconsistency just seems wrong. That has been discussed numerous times on ruby-talk. That last discussion is just a few weeks back. Bottom line: syntactic order in the source determines from when on a local variable is defined. Cheers robert