class Doing::FluentEnumerator
Attributes
enumerator[R]
Public Class Methods
new(enumerator)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 13 def initialize(enumerator) @enumerator = enumerator.lazy end
Public Instance Methods
each(&block)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 17 def each(&block) block ||= Proc.new{} enumerator.each(&block) end
inject(*args, &block)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 30 def inject(*args, &block) FluentValue.new(enumerator.send(:inject, *args, &block)) end
Also aliased as: reduce
method_missing(method, *args, &block)
click to toggle source
# 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
Private Instance Methods
map_elements(method, *args, &block)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 56 def map_elements(method, *args, &block) map do |e| if e.respond_to?(method) e.send(method, *args, &block) else Kernel.send(method, *args.clone.unshift(e), &block) end end end
predicate?(method)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 38 def predicate?(method) method.to_s.end_with?("?") end
remove_question_marks(method)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 52 def remove_question_marks(method) method.to_s.gsub(/\?/, "") end
select_elements(method, *args, &block)
click to toggle source
# File lib/doing/fluent_enumerator.rb, line 42 def select_elements(method, *args, &block) select do |e| if e.respond_to?(method) e.send(method, *args, &block) elsif e.respond_to?(remove_question_marks(method)) e.send(remove_question_marks(method), *args, &block) end end end