From: "Llelan D." Date: 2012-05-24T14:30:25+09:00 Subject: Re: looking for a ruby idiom : r=foo; return r if r botp wrote in post #1061908: > return r if (r=foo) > > but ruby complains w(ith) undefined r This is a BUG! The expression after an IF does not define new scope, you're still in the containing scope. This means the initial statement of the if-modifier is validating the scope of any local variables before the if-modifier expression is evaluated. According to the "Ruby Standardization WG Draft August 25, 2010" Section 12.3 The if modifier statement Page 107 --------- Semantics An if-modifier-statement of the form S if E, where S is the statement and E is the expression, is evaluated as follows: a) Evaluate the if-expression of the form if E then S end. b) The value of the if-modifier-statement is the resulting value. --------- The Semantics section item 'a' clearly states that the if-modifier should be interpreted in the same manner as the equivalent single-line if-expression. This means that the initial statement should not be validating local variables until after the modifier expression is evaluated, possibly initializing new local variables for use in the initial statement. Please report this as an interpretor bug. -- Posted via http://www.ruby-forum.com/.