each_with_index

each_with_index

ri

 --------------------------------------------- Enumerable#each_with_index
      enum.each_with_index {|obj, i| block }  -> enum
 ------------------------------------------------------------------------
      Calls _block_ with two arguments, the item and its index, for each
      item in _enum_.
 
         hash = Hash.new
         %w(cat dog wombat).each_with_index {|item, index|
           hash[item] = index
         }
         hash   #=> {"cat"=>0, "wombat"=>2, "dog"=>1}
 

refe

 Enumerable#each_with_index
 --- each_with_index {|item,index| ... }
 
     要素とインデックスを両方与えるイテレータ。
 
     self を返します。