DEV Community

Cover image for 4 lesser known ways to use Ruby’s Enumerable module

4 lesser known ways to use Ruby’s Enumerable module

Josh Dzielak 🔆 on May 22, 2019

A big reason I love Ruby is how much work I can get done in just a few characters or lines of code, and ensuring that code is still easy to read fo...
Collapse
 
darkwiiplayer profile image
𒎏Wii 🏳️‍⚧️

Enumerable#lazy probably deserves its own article. It's a great feature if you want your code to be nice to read but still somewhat performant.

Collapse
 
coreyja profile image
Corey Alexander

Ya this is the one that was new to me from the list! Would love to read an article on it alone

Collapse
 
sannim1 profile image
Abdulmusawwir Sanni

Great article. Thanks for sharing this knowledge 🙏


However, the first element of the next array is the last element of the previous

While describing the behaviour of each_cons, you mention the above. I think that may not be 100% accurate in all cases, as the first element of the next array is actually the second element of the previous.

It just so happens to be correct for the accompanying example because the returned arrays are of size 2.

Hope that makes sense 🙂

Collapse
 
dzello profile image
Josh Dzielak 🔆

Thanks for reading!

Good catch there 😅 I've updated the post to state that correctly, thank you for pointing it out.

Collapse
 
vinibrsl profile image
Vinicius Brasil

Thanks for sharing. We have endless ranges at last! No more Float::INFINITY-ish solutions.