缩短枚举代码
在 Ruby 中实现这一点的简洁方法是什么? 我只想等到所有对象都运行起来。这似乎太罗嗦了。
# arr contains objects that respond to running?
all_running = false
until all_running
sleep 0.5
all_running = true
arr.each{ |obj|
all_running = all_running and obj.running?
}
end
What is a succinct way of accomplishing this in Ruby?
I simply want to wait until all objects are running. This seems too wordy.
# arr contains objects that respond to running?
all_running = false
until all_running
sleep 0.5
all_running = true
arr.each{ |obj|
all_running = all_running and obj.running?
}
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
怎么样
sleep(0.5) 直到 arr.inject(true) { |all_running, obj| ? all_running 和 obj.running? }
How about
sleep(0.5) until arr.inject(true) { |all_running, obj| all_running and obj.running? }