Re:Ruby 3.0.0 RC1
by dragonwriter on Monday December 21, 2020 @02:01PM
(#25498163)
> Even in Ruby, no one uses loops, they use Enumerable.
Enumerable#each is quite deeply equivalent to a for…in loop.
But no one uses for loops in Ruby because not only are they basically an alternate syntax for Enumerable#each, but they became non-idiomatic because in earlier versions (through at least 1.8.x, IIRC; I think this may have been resolved by the switch to YARV in 1.9) “for” had some implementation inefficiencies which made it notably slower than #each.
Reduce (inject, etc.) are tricky to understand at first but once you do, you realize the power in it. Granted, it’s harder to understand than loops, but loops with iteration and mutability get you into a lot more trouble.
It sounds like you’re simply not over the learning curve yet.