Skip to content

Instantly share code, notes, and snippets.

@tyler-smith
Created October 9, 2012 00:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tyler-smith/3855764 to your computer and use it in GitHub Desktop.
Save tyler-smith/3855764 to your computer and use it in GitHub Desktop.
Array#bifurcate
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