Enumerable#partition
Ever want to do a select and reject at the same time? Use partition. Here's a super fast way to get all the evens and odds from 1 to 100.
even, odd = [*1..100].partition(&:even?)
Written by David Kormushoff
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#