In C you can use statement blocks to isolate local variables from its parent scope.
int foo() {
{
int a;
}
// Here `a` is no longer in the scope.
}
But in Ruby the following fails to parse.
def foo
do
a = 1
end
puts a
end
Is there a trick to isolate variables into a scope in Ruby?
begin ... end, notdo ... end.def,classandmodule.begin; a = 1; end; puts aprints 1, soais not confined to the scope of the begin block.