Skip to content

Instantly share code, notes, and snippets.

@bradherman
Created April 4, 2013 22:33
Show Gist options
  • Save bradherman/5314957 to your computer and use it in GitHub Desktop.
Save bradherman/5314957 to your computer and use it in GitHub Desktop.
Array method that will pull out and return matching items from the array, leaving non-matching items in the original.
class Array
def pop_if!(&block)
a,b = self.partition(&block)
self.replace(b)
a
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment