以下是两个执行相同操作的简单块:
a = (0..100).to_a a.all? do |x| !(x == 1000) end nil == a.index do |x| x == 1000 end
除了第二个一直快一点.为什么?
user system total real testing all 1.140000 0.000000 1.140000 ( 1.144535) testing index 0.770000 0.000000 0.770000 ( 0.769195)