method
each_with_index

Ruby latest stable (v2_5_5)
-
0 notes -
Class: Enumerable
each_with_index(*args)
public
Calls block with two arguments, the item and its index, for each item in enum. Given arguments are passed through to #each().
If no block is given, an enumerator is returned instead.
hash = Hash.new %w(cat dog wombat).each_with_index { |item, index| hash[item] = index } hash #=> {"cat"=>0, "dog"=>1, "wombat"=>2}