Skip to content
Create a gist now

Instantly share code, notes, and snippets.

test variables are shared between threads
# testing out class variables are shared between instances
require 'thread'
class A
@m =
@@m =
M =
def self.m; @m end
def; @@m end
def self.mmm; M end
puts "nil #{nil.object_id}"
@output = {}
def gather_output
name = "Thread #{Thread.current.object_id}"
@output[name] = []
@output[name] << "c #{A}"
@output[name] << "@m #{A.m}"
@output[name] << "@@m #{}"
@output[name] << "M #{A.mmm}"
threads = []
3.times do
threads <<
gather_output &:join
@output.each_pair do |name, o|
puts [name, o].inspect
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.