Created
May 4, 2012 20:29
-
-
Save mjtko/2597530 to your computer and use it in GitHub Desktop.
Subset for a set
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
require 'set' | |
class Set | |
def subset(&pred) | |
Set.new.tap do |subset| | |
each do |x| | |
subset << x if pred.call(x) | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
eg.