Class: Fabulator::Expr::ForExpr

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

Direct Known Subclasses

EveryExpr, SomeExpr

Instance Method Summary collapse

Constructor Details

#initialize(v, e) ⇒ ForExpr

Returns a new instance of ForExpr.



4
5
6
7
8
9
10
11
12
# File 'lib/fabulator/expr/for_expr.rb', line 4

def initialize(v, e)
  if v.size > 1
    @var = v.shift
    @expr = Fabulator::Expr::ForExpr.new(v, e)
  else
    @var = v.first
    @expr = e
  end
end

Instance Method Details

#expr_type(context) ⇒ Object



14
15
16
# File 'lib/fabulator/expr/for_expr.rb', line 14

def expr_type(context)
  @expr.expr_type(context)
end

#run(context, autovivify = false) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/fabulator/expr/for_expr.rb', line 18

def run(context, autovivify = false)
  result = [ ]
  return result if @var.nil? || @expr.nil?

  count = 1
  @var.each_binding(context, autovivify) do |b|
    b.position = count
    result = result + @expr.run(b)
    count += 1
  end
  return result
end