Method: Enumerable#each_with_index

Defined in:
enum.c

#each_with_index {|obj, i| ... } ⇒ Enumerator

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}

Yields:

  • (obj, i)

Returns:

  • (Enumerator)


806
807
808
# File 'enum.c', line 806

static VALUE
enum_each_with_index(obj)
VALUE obj;