DEV Community

Discussion on: Understanding Ruby - For vs Each

Collapse
 
beyarz profile image
Beyar

I didn't know that for loop leaks the variable while each does not!

Collapse
 
vgoff profile image
Victor Goff

And each is not an Enumerable, but a dependency of Enumerable. So depending on how each is implemented, there is no guarantee that leaks do not happen. The method, probably stated obviously, does not even need to be an "iterator" but could be whatever. (don't do that though! :) )