Module: Trxl::Variable1

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#bind(value, env) ⇒ Object



4448
4449
4450
# File 'lib/trxl/trxl_grammar.rb', line 4448

def bind(value, env)
  env.merge(text_value.to_sym => value)
end

#eval(env = Environment.new) ⇒ Object



4440
4441
4442
4443
4444
4445
4446
# File 'lib/trxl/trxl_grammar.rb', line 4440

def eval(env = Environment.new)
  if env.has_key?(name)
    env[name]
  else
    raise(Trxl::MissingVariableException, "variable #{name} is not defined")
  end
end

#nameObject



4461
4462
4463
# File 'lib/trxl/trxl_grammar.rb', line 4461

def name
  text_value.to_sym
end

#to_s(env = Environment.new) ⇒ Object



4452
4453
4454
4455
4456
4457
4458
4459
# File 'lib/trxl/trxl_grammar.rb', line 4452

def to_s(env = Environment.new)
  if env.has_key?(name)
    value = env[name]
    (value.is_a?(Array) || value.is_a?(Hash)) ? value.inspect : value.to_s
  else
    text_value
  end
end