So I'm starting to learn Ruby and found a great resource, Learn Ruby in Y minutes. It's great, very fast paced as I expected, since I'm an experienced JS developer.
But I got to the Loops part and something really caught my attention. It says the following syntax is preferable:
(1..5).each do |counter| to this one for counter in 1..5. Now, it may be my javascript developer side speaking, but the second form looks better/cleaner to me. Am I insane or is there a reason for the first form to be more common than the second one? Are there any performance differences?
Thank you all.









Performance differences seem negligible gist.github.com/jodosha/229951
As for better/cleaner, Rubyists definitely love
.each, and for practical purposes, it's probably worth just drinking the kook-aid rather than stirring things up with Ruby dogma.But I'm happy to hear the bikeshedding on this. 😄