【发布时间】:2017-09-09 22:37:39
【问题描述】:
在为飓风厄玛做准备时,我写了一个快速垃圾脚本来从 exercism.io 下载一堆练习。它可以工作,但是在调用threads.each 时出现我不理解的错误,如果我理解正确,直到threads.each 的所有代码都是同步的,所以我不确定修复的最佳方法是什么。 :
rb:14:in '<main>': undefined method 'each' for nil:NilClass (NoMethodError)
这对我来说很有趣,因为我收到了错误,但程序仍然按预期运行,所以我确定我写得不对。
language = ARGV[0]
exercises = `exercism list #{@language}`.split("\n")
threads = exercises.map do |exercise|
break if exercise == ''
Thread.new do
system("exercism fetch #{language} #{exercise}")
end
end
threads.each(&:join)
【问题讨论】:
标签: ruby multithreading