Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.ruby > #6692
| From | Robert Klemme <shortcutter@googlemail.com> |
|---|---|
| Newsgroups | comp.lang.ruby |
| Subject | Re: How undefined values are handled with 'if' modifier. |
| Date | 2012-12-08 10:34 +0100 |
| Message-ID | <aigfshFu3h7U1@mid.individual.net> (permalink) |
| References | <7a182ec4-9f34-490b-9ac1-30f49f904b06@googlegroups.com> |
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
Back to comp.lang.ruby | Previous | Next — Previous in thread | Find similar
How undefined values are handled with 'if' modifier. michael.j.cannon@gmail.com - 2012-12-07 10:02 -0800 Re: How undefined values are handled with 'if' modifier. Robert Klemme <shortcutter@googlemail.com> - 2012-12-08 10:34 +0100
csiph-web