Get number of times in loop over Hash object

Posted by Matt Huggins on Stack Overflow See other posts from Stack Overflow or by Matt Huggins
Published on 2010-04-08T15:42:39Z Indexed on 2010/04/08 15:53 UTC
Read the original article Hit count: 282

Filed under:
|
|
|
|

I have an object of type Hash that I want to loop over via hash.each do |key, value|. I would like to get the number of times I've been through the loop starting at 1.

Is there a method similar to each that provides this (while still providing the hash key/value data), or do I need to create another counter variable to increment within the loop?

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby