Class: EnumerableFu::Filter

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/enumerable_fu/filtering.rb

Instance Method Summary collapse

Methods included from Enumerable

#collecting, #rejecting, #selecting, #uniqing, #uniqing_by

Constructor Details

#initialize(&generator) ⇒ Filter

Returns a new instance of Filter.


9
10
11
# File 'lib/enumerable_fu/filtering.rb', line 9

def initialize(&generator)
  @generator = generator
end

Instance Method Details

#eachObject


13
14
15
16
17
# File 'lib/enumerable_fu/filtering.rb', line 13

def each
  return to_enum unless block_given?
  yielder = proc { |x| yield x }
  @generator.call(yielder)
end