Class: Fabulator::Expr::Var

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

Instance Method Summary collapse

Constructor Details

#initialize(v) ⇒ Var

Returns a new instance of Var.



19
20
21
# File 'lib/fabulator/expr/literal.rb', line 19

def initialize(v)
  @var = v
end

Instance Method Details

#expr_type(context) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/fabulator/expr/literal.rb', line 23

def expr_type(context)
  v = context.get_var(@var)
  if( v.is_a?(Array) )
    TagLib.unify_types(v.collect{ |i| i.vtype })
  else
    v.vtype
  end
end

#run(context, autovivify = false) ⇒ Object



32
33
34
35
36
# File 'lib/fabulator/expr/literal.rb', line 32

def run(context, autovivify = false)
  v = context.get_var(@var)
  return [] if v.nil?
  return v.is_a?(Array) ? v : [ v ]
end