-
-
Save yorickpeterse/897a68bec747b604b5b3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'thread' | |
root = File.expand_path('../lib/constants', __FILE__) | |
constants = Queue.new | |
numbers = (1..5000).to_a | |
numbers.shuffle.each do |number| | |
name = "B#{number}" | |
path = File.join(root, "b#{number}.rb") | |
a_path = File.join(root, "a#{number}.rb") | |
a_number = numbers.sample | |
File.open(path, 'w') do |handle| | |
handle.puts <<-EOF | |
class #{name} | |
autoload :A#{a_number}, #{a_path.inspect} | |
end | |
EOF | |
end | |
constants << name | |
Object.autoload(name, path) | |
end | |
numbers.shuffle.each do |number| | |
name = "A#{number}" | |
path = File.join(root, "a#{number}.rb") | |
File.open(path, 'w') do |handle| | |
handle.puts <<-EOF | |
class #{name} | |
end | |
A#{numbers.sample} | |
EOF | |
end | |
constants << name | |
Object.autoload(name, path) | |
end | |
Thread.abort_on_exception = true | |
threads = 50.times.map do | |
Thread.new do | |
loop do | |
break if constants.size == 0 | |
Object.const_get(constants.pop) | |
end | |
end | |
end | |
threads.each(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment