Created
October 9, 2012 00:13
-
-
Save tyler-smith/3855764 to your computer and use it in GitHub Desktop.
Array#bifurcate
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def bifurcate(&block) | |
self.each_with_object([[],[]]){|el, ary| ary[yield(el) ? 0 : 1] << el } | |
end | |
end | |
evens, odds = (1..10).to_a.bifurcate{|el| el % 2 == 0} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment