Class: LazyList::ListBuilder::ListBuilderProc

Inherits:
Proc
  • Object
show all
Includes:
DSLKit::BlockSelf, DSLKit::MethodMissingDelegator
Defined in:
lib/lazylist/list_builder.rb

Overview

This class is a special kind of Proc object, that uses instance_eval to execute a code block.

Instance Method Summary collapse

Constructor Details

#initialize(lb, name, &block) ⇒ ListBuilderProc

Creates a ListBuilderProc working on the list builder lb using the Proc returned by lb.#name. name has to be either :filter or :transform.



50
51
52
53
54
55
# File 'lib/lazylist/list_builder.rb', line 50

def initialize(lb, name, &block)
  @name = name
  @lb = lb
  @method_missing_delegator = block_self(&block)
  super(&@lb.__send__(@name))
end

Instance Method Details

#call(*args) ⇒ Object Also known as: []

Call this ListBuilderProc instance with the arguments args, which have to be the ordered values of the variables.



59
60
61
62
63
64
65
# File 'lib/lazylist/list_builder.rb', line 59

def call(*args)
  prepare_variables
  @lb.variables.each_with_index do |var, i|
    instance_variable_set "@#{var}", args[i]
  end
  instance_eval(&@lb.__send__(@name))
end