Module: Trxl::OffsetAccessExp1

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#eval(env = Environment.new) ⇒ Object



3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
# File 'lib/trxl/trxl_grammar.rb', line 3854

def eval(env = Environment.new)
  var = variable.eval(env)
  if var.is_a?(Array) || var.is_a?(Hash) || var.is_a?(String)
    result = left_associative_apply(var, offset_specifier_exp.eval(env))
    var.is_a?(String) ? result.chr : result
  else
    msg = "Indexing is not possible for #{var.class} (only Arrays and Strings allowed)"
    raise Trxl::InvalidOperationException, msg
  end
end