This is a Ruby tree! It shows every object from the Ruby Programming Language in a tree format.

each_index

        # Array.each_index

(from ruby core)
---
    array.each_index {|index| ... } -> self
    array.each_index -> Enumerator

---

Iterates over array indexes.

When a block given, passes each successive array index to the block;
returns `self`:
    a = [:foo, 'bar', 2]
    a.each_index {|index|  puts "#{index} #{a[index]}" }

Output:
    0 foo
    1 bar
    2 2

Allows the array to be modified during iteration:
    a = [:foo, 'bar', 2]
    a.each_index {|index| puts index; a.clear if index > 0 }

Output:
    0
    1

When no block given, returns a new Enumerator:
    a = [:foo, 'bar', 2]
    e = a.each_index
    e # => #<Enumerator: [:foo, "bar", 2]:each_index>
    a1 = e.each {|index|  puts "#{index} #{a[index]}"}

Output:
    0 foo
    1 bar
    2 2

Related: #each, #reverse_each.



      

This is MURDOC! A Ruby documentation browser inspired by Smalltalk-80. It allows you to learn about Ruby by browsing through its class hierarchies, and see any of its methods.