这里有两个做同样事情的简单块:
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)