Created
April 4, 2013 22:33
-
-
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.
This file contains hidden or 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 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