Hi,
Ruby 1.9 gives the ability to define variables that are just local to a block and do not close over variables of the same name in an outer scope:
x = 10
proc { |;x|
x = 20
}.call
x #=> 10
I would like to have this behaviour as default for some blocks i define - without having to use the |;x, y, z| syntax (note the semicolon).
I do not think Ruby allows this natively but is it possible to hack this functionality in ?
I have one solution currently but it's quite ugly as it requires checking to see which locals have changed at the end of a block and then reverting them to their values prior to the block. I do not mind if your solution requires specifying which variables are block-local at the start of the block i.e scope(:x) { x = 20 }
thanks!