True local variables (not accessible from outside) : Thread.new « Threads « Ruby






True local variables (not accessible from outside)


thread = Thread.new do
  t = Thread.current
  t["var3"] = 25
  t[:var4] = "foobar"
  var3 = 99            # True local variables (not accessible from outside)
  var4 = "zorch"       
end

a = thread[:var3]      # 25
b = thread["var4"]     # "foobar"

 








Related examples in the same category

1.Create threads in a while loop
2.Pass value into a thread
3.Use upto to create 3 threads
4.manipulate variables from the outer scope
5.Access the thread-local data from outside