each_index is an Enumerable that goes through all the indexes and performs an action for each of them. When this is done, he will return your original collection , as it is not his job to change it. If you want to display material using puts / print , then each_index is fine.
If you want to create a new collection as a result of going through all the elements of the original collection, you must use map ,
eg.
array = [['a', 'b', 'c'], ['d', 'e', 'f'], ['g', 'h', 'i']] new_array = array.map {|el| el[2]} => ["c", "f", "i"]
array.map iterates through the elements of the array, so at each step | el | it is an element, not an index, as in: ['a', 'b', 'c'] in the first iteration, ['d', 'e', 'f'] in the second, etc ...
Just pointing this out, as I donβt know what the purpose of what you are trying to do is.
ellmo source share