Class: Doing::FluentEnumerator

Inherits:
Object
  • Object
show all
Extended by:
EnumeratorWrapper, Forwardable
Defined in:
lib/doing/fluent_enumerator.rb

Instance Method Summary collapse

Methods included from EnumeratorWrapper

wrap

Constructor Details

#initialize(enumerator) ⇒ FluentEnumerator

Returns a new instance of FluentEnumerator.



13
14
15
# File 'lib/doing/fluent_enumerator.rb', line 13

def initialize(enumerator)
  @enumerator = enumerator.lazy
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



22
23
24
25
26
27
28
# File 'lib/doing/fluent_enumerator.rb', line 22

def method_missing(method, *args, &block)
  if predicate?(method)
    select_elements(method, *args, &block)
  else
    map_elements(method, *args, &block)
  end
end

Instance Method Details

#each(&block) ⇒ Object



17
18
19
20
# File 'lib/doing/fluent_enumerator.rb', line 17

def each(&block)
  block ||= Proc.new{}
  enumerator.each(&block)
end

#inject(*args, &block) ⇒ Object Also known as: reduce



30
31
32
# File 'lib/doing/fluent_enumerator.rb', line 30

def inject(*args, &block)
  FluentValue.new(enumerator.send(:inject, *args, &block))
end