是的,你可以
some_array[offset..-1].each_with_index{|item, index| some_func(item, index) }
some_array[offset..-1].each_with_index{|item, index| some_func(item, index+offset) }
some_array[offset..-1].each_with_index{|item, index| index+=offset; some_func(item, index) }
UPD
另外我应该注意到,如果偏移量大于你的数组大小,它会出错。因为:
some_array[1000,-1] => nil
nil.each_with_index => Error 'undefined method `each_with_index' for nil:NilClass'
我们可以在这里做什么:
(some_array[offset..-1]||[]).each_with_index{|item, index| some_func(item, index) }
或预先验证偏移量:
offset = 1000
some_array[offset..-1].each_with_index{|item, index| some_func(item, index) } if offset <= some_array.size
这有点骇人听闻
UPD 2
就您更新问题而言,现在您不需要数组偏移量,而是索引偏移量,因此@sawa 解决方案将适合您