I would like to access the size of the enumerator from within the block, like this:
["cat", "dog", "mouse"].each_with_index { |e, i| puts "#{i + 1} of #{x.size}: #{e}" }
Where x would be the array that runs each_with_index.
I tried the tap method, but that did not work the way I thought it would.
For example, this code seems OK, I guess:
["cat", "dog", "mouse"].tap { |a| a.each_with_index { |e, i| puts "#{i + 1} of #{a.size}: #{e}" }} # Works, but why do I need two blocks?
I was hoping to do it using just one block, not two. Like this:
["cat", "dog", "mouse"].each_with_index.tap { |a, e, i| puts "#{i + 1} of #{a.size}" } # Does not work