We can assign a local thread variable to Ruby, for example:
Thread.current[:foo] = 1 Thread.current[:bar] = 2
But how do we list / list these variables later?
You can get the keys using Thread#keys :
Thread#keys
Thread.current[:foo] = 1 Thread.current[:bar] = 2 Thread.current.keys # => [:__recursive_key__, :foo, :bar]
I donβt know how useful this is because you need to know which keys you are using.
Thread.list.each { |t| p "T #{t.object_id} tvars:#{t.thread_variables.length} numkeys:#{t.keys.length}" }