method

enum_with_index

ruby latest stable - Class: Enumerable

Method deprecated or moved

This method is deprecated or moved on the latest stable version. The last existing version (v1_8_7_330) is shown here.

enum_with_index()
public

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}

1Note

Needs requiring 'enumerator' to work

yonosoytu ยท Aug 23, 2008

This method needs that you

require 'enumerator'

for this method to be available.