Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save willnet/a67beba9a9f19cfd7d06f055a38c11f5 to your computer and use it in GitHub Desktop.

Select an option

Save willnet/a67beba9a9f19cfd7d06f055a38c11f5 to your computer and use it in GitHub Desktop.
Ruby の thread とクロージャ
require 'thread'
hash = {}
a = Thread.new do
connection = 'A'
hash[:a] = -> { puts connection }
end
b = Thread.new do
connection = 'B'
hash[:b] = -> { puts connection }
end
a.join
b.join
c = Thread.new do
connection = 'C'
hash[:a].call
hash[:b].call
end
c.join
@willnet

willnet commented May 8, 2016

Copy link
Copy Markdown
Author

A
B

と出力される

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment