Skip to content

Instantly share code, notes, and snippets.

@choallin
Created June 18, 2019 16:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choallin/ab13c168690fb4f2cc5ac679f04424b8 to your computer and use it in GitHub Desktop.
Save choallin/ab13c168690fb4f2cc5ac679f04424b8 to your computer and use it in GitHub Desktop.
4.times.map do
t = Thread.current
t["#{dynamic_variable_name}".to_sym] = method_call
end
joined_threads = threads.map &:join
joined_threads.each do |t|
# The keys method returns all thread local variables by names
# analog to the Hash#keys method
t.keys.each do |key|
k = key.to_s.downcase
next if k.start_with?("active") || k.start_with?("__")
# In this example we want to have access to all this variables
# as an instance variabel e.g. to use them in a Rails view
instance_variable_set "@#{key}", t[key]
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment