如何使用每个迭代器获取数组索引或迭代次数?

我正在迭代遍历ruby中的数组。 有没有一种简单的方法可以获得迭代次数或数组索引而无需返回for循环?

啊,明白了。

each_with_index 

呜!

编辑:哎呀!

为了完整起见。

 Thing.each_with_index {|obj, index_num| puts [obj, index_num].join(" has an index of ")}