I have a variable which I set a default value on, and then I perform a procedure on. The thing is, I don't have access to the variable inside the block as the block has it's own variable scope and no access to the outside. Here is a snippet:
value = ""
cmd_errors = Array.new
# Call the command line
status = POpen4.popen4(cmd) do |stdout, stderr|
output = stdout.read
error = stderr.read
if (!output.empty?)
value = JSON.parse(output) #This just creates a block scoped variable called 'value' and my local variable is still empty
else
cmd_errors << error
end
end
Is it possible to allow the block to write to that local variable? Perhaps using references?
p output,errorwithin the loop. Seems theifcondition never becomes true.p xis equivalent toputs x.inspect, so you shouldn't writep value.inspectas it is the same asputs x.inspect.inspectwhich messes things up badly.