Skip to content

Instantly share code, notes, and snippets.

@shugo
Created December 27, 2019 17:01
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 shugo/a23118ff9344ea0b968cffacb09186ab to your computer and use it in GitHub Desktop.
Save shugo/a23118ff9344ea0b968cffacb09186ab to your computer and use it in GitHub Desktop.
module M1
refine String do
def foo
"M1#foo"
end
end
end
module M2
refine String do
def foo
"M2#foo"
end
end
end
def bar(m, &block)
block.using(m)
Thread.pass
block.call
end
using Proc::Refinements
100.times.map { |i|
Thread.new(i.even? ? M1 : M2) { |m|
bar(m) {
p [m, "x".foo, Module.used_modules]
}
}
}.each(&:join)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment