I came across a weird behaviour in Ruby that I can't explain.
If we have an array of arrays and wanted to iterated over it with map. I tried to use map with two block variables expecting the second one to be the index, but it instead takes the values of the inner array. Why?
persons = [["john", 28], ["mary", 25],["emma", 30]]
persons.map do |param1, param2|
puts param1
puts param2
end
The output is
john
28
So how come that it takes the values of the iterators it should iterate over?
with_index.a,b =["john", 28]. Now b == 28mapyields two values, the second one of which is the index? That is completely wrong, and it would be interesting to know where you found such documentation, so that we can warn future programmers about its in-accuracies and/or contact the responsible person and ask them to correct it.