Parent

Files

LazyList::ListBuilder

This class encapsulates a list builder (ListBuilder), that can be transformed into a LazyList, by calling LazyList::ListBuilder#where.

Attributes

variables[R]

The variable names defined in this list builder.

transform[R]

The transform ListBuilderProc instance of this list builder.

filter[R]

The filter ListBuilderProc of this list builder or nil.

Public Class Methods

create_build(&block) click to toggle source

Used to support the build method

# File lib/lazylist/list_builder.rb, line 126
      def create_build(&block)
        new(:do_build, &block)
      end
create_comprehend(&block) click to toggle source

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
new(mode, &block) click to toggle source

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

Public Instance Methods

inspect() click to toggle source

Alias for to_s

to_s() click to toggle source

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
Also aliased as: inspect
where(sources = {}, &block) click to toggle source

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.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.