From: Sylvain Joyeux Date: 2008-09-22T17:26:10+09:00 Subject: Re: for or each? On Sun, Sep 21, 2008 at 07:12:06AM +0900, Phlip wrote: > tekwiz wrote: > >>>> It leaves you closer to a refactor to .map or .inject or .select or >>>> .reject or .delete_if or .each_index or .each_with_index or ... > >> So, it's a code-readability issue and not a functional or complexity >> issue? > > 'for' is arguably more readable. And it's not a performance issue - I > suspect the opcodes will be the same. It is very much a technical issue. Nope. each { } needs one new scope for each iteration while "for ... in" explicitely uses the parent scope... In the end, you create with #each as many objects as there are in your collection - which can be a huge performance hit in some cases. That's why I personally use "for ... in" in performance-critical parts of my code, to avoid unnecessary GC. Sylvain