Class: Enumerating::Filter
- Inherits:
-
Object
- Object
- Enumerating::Filter
- Includes:
- Enumerable
- Defined in:
- lib/enumerating/filtering.rb
Constant Summary collapse
- DONE =
"done-#{self.object_id}".to_sym
Instance Method Summary collapse
- #each ⇒ Object
-
#initialize(&generator) ⇒ Filter
constructor
A new instance of Filter.
Methods included from Enumerable
#[], #collecting, #dropping, #dropping_while, #prefetching, #rejecting, #selecting, #taking, #taking_while, #threading, #uniqing, #uniqing_by
Constructor Details
#initialize(&generator) ⇒ Filter
Returns a new instance of Filter.
9 10 11 |
# File 'lib/enumerating/filtering.rb', line 9 def initialize(&generator) @generator = generator end |
Instance Method Details
#each ⇒ Object
15 16 17 18 19 20 21 |
# File 'lib/enumerating/filtering.rb', line 15 def each return to_enum unless block_given? yielder = proc { |x| yield x } catch DONE do @generator.call(yielder) end end |