I've found this aspect of Ruby's otherwise very intuitive
syntax to be "surprising" too.  Yes, I understand why:

 ... do something wth local variable ...  if/unless/while variable = expr

is evaluated as it is.

As others have mentioned, the real problem is that
these constructs are evaluated
in a different order than they are parsed.

Consider:
If one wants to force (x) to be interpreted as a method,
one can always write (self.x), but there really is no
analog for forcing (x) to be interpreted as a local variable.
The only way a know is to assign to it, as in:

x = nil
put x if x = expr

This works, but it is not elegant by any stretch of the
imagination.

Has anyone considered a syntax for hinting to the
parser that an identifier be interpreted as a local variable?

Something like:

@@@x

for example?

Thus, one would write:

put @@@x if x = expr

Please don't get hung up on '@@@'. I just choose
it to because ruby already uses @ and @@ for indicate
identifier types/classes.

Something shorter would be better.

-- 
 Brent Roman
 Software Engineer                 Tel: 831 775 1808
 425 Clinton St., Santa Cruz,      California, 95062
 mailto:brent / mbari.org  http://www.mbari.org/~brent