Skip to content

Instantly share code, notes, and snippets.

@aileron
Created April 4, 2012 19:50
Show Gist options
  • Save aileron/2305094 to your computer and use it in GitHub Desktop.
Save aileron/2305094 to your computer and use it in GitHub Desktop.
sexy enumerator
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