Mega Code Archive

 
Categories / Ruby / Threads
 

Access the thread-local data from outside

thread = Thread.new do   t = Thread.current   t[:var1] = "This is a string"   t[:var2] = 365 end x = thread[:var1]               # "This is a string" y = thread[:var2]               # 365 has_var2 = thread.key?("var2")  # true has_var3 = thread.key?("var3")  # false