Public: Technology Reviews : Ruby Tips - Pitfalls
This page last changed on Apr 13, 2009 by skim.
Consider the following code.
One should naturally expect that x in the block following "a.each" is local to that block and that the output of this code will be "x=0". Yet the actual output is "x=3" as of ruby 1.8.7.
So at this point one should again naturally conclude that x is global so that the following code will print "x=3".
But the actual output is
The confusing matter of fact is, for a block variable x,
Consider the following irb session:
Only the first line meets one's intuition, because "&&" has higher precedence than "||".
The 2nd and 3rd happens because "and" and "or" has the same precedence, and "||" has higher precedence than "and".
|Document generated by Confluence on Jan 27, 2014 16:56|