Skip to content

Instantly share code, notes, and snippets.

@dekz

dekz/each.rb Secret

Created March 24, 2012 07:18
Show Gist options
  • Save dekz/1beb0e743fe0bd6cbbea to your computer and use it in GitHub Desktop.
Save dekz/1beb0e743fe0bd6cbbea to your computer and use it in GitHub Desktop.
Use new block scopes
p 'before'
threads = []
(0..5).each do |i|
threads << Thread.new do
p i
end
end
p 'after'
threads.each { |t| t.join }
"before"
0
1
2
3
4
5"after"
"before"
0
1
2
3
4
"after"
5
"before"
"after"
0
3
4
1
2
5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment