This class encapsulates a list builder (ListBuilder), that can be transformed into a LazyList, by calling LazyList::ListBuilder#where.
Used to support the build method
# File lib/lazylist/list_builder.rb, line 126 def create_build(&block) new(:do_build, &block) end
Used to evaluate a list comprehension, usually if calling the list method with only a block.
# File lib/lazylist/list_builder.rb, line 132 def create_comprehend(&block) new(:do_comprehend, &block) end
Creates LazyList::ListBuilder instance. mode has to be either :do_build or :do_comprehend.
# File lib/lazylist/list_builder.rb, line 82 def initialize(mode, &block) @mode = mode @transform = ListBuilderProc.new(self, :transform, &block) end
Return a (not much) nicer string representation of the list builder.
# File lib/lazylist/list_builder.rb, line 119 def to_s "#<LazyList::ListBuilder>" end
This method creates a LazyList instance from this list builder, using the sources hash to fetch the variables from. sources consists of the variable name and the values, that can be LazyList instances or otherwise they will be transformed into a LazyList with LazyList.[].
It also takes a block, to filter the results by a boolean expression.
# File lib/lazylist/list_builder.rb, line 102 def where(sources = {}, &block) @variables = [] generators = [] sources.each do |var, src| @variables << var generators << (src.is_a?(LazyList) ? src : LazyList[src]) end if block_given? @filter = ListBuilderProc.new(self, :filter, &block) else @filter = nil end generators.first.__send__(@mode, self, generators[1..-1]) end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.