Created
April 4, 2012 19:50
-
-
Save aileron/2305094 to your computer and use it in GitHub Desktop.
sexy enumerator
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 Enumerator | |
def filter(c=nil,&b) | |
s = self | |
e = ::Enumerator.new do |y| | |
s.each do |x| | |
y << (c||b).call(x) | |
end | |
end | |
return e unless c | |
e.each &b | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment