Ruby 2.4

IndexError

IndexError类

Parent:StandardError

当给定索引无效时引发。

a = [:foo, :bar] a.fetch(0) #=> :foo a[4] #=> nil a.fetch(4) #=> IndexError: index 4 outside of array bounds: -2...2