Class: Fabulator::Expr::ForVar

Inherits:
Object
  • Object
show all
Defined in:
lib/fabulator/expr/for_expr.rb

Instance Method Summary collapse

Constructor Details

#initialize(n, e) ⇒ ForVar

Returns a new instance of ForVar.



61
62
63
64
65
# File 'lib/fabulator/expr/for_expr.rb', line 61

def initialize(n, e)
  n =~ /^\$?(.*)$/
  @var_name = $1
  @expr = e
end

Instance Method Details

#each_binding(context, autovivify = false, &block) ⇒ Object



67
68
69
70
71
72
73
74
# File 'lib/fabulator/expr/for_expr.rb', line 67

def each_binding(context, autovivify = false, &block)
  @expr.run(context, autovivify).each do |e|
    context.in_context do |ctx|
      ctx.set_var(@var_name, e)
      yield ctx
    end
  end
end