Module: Trxl::WhenExpression1

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#eval(env = Environment.new) ⇒ Object



1266
1267
1268
1269
1270
1271
1272
1273
1274
# File 'lib/trxl/trxl_grammar.rb', line 1266

def eval(env = Environment.new)
  condition = when_exp.eval(env)
  expression = statement_list.eval(env)
  {
    # use '' instead of "" since we don't care about var replacement now
    :condition =>  ruby_when_condition(condition),
    :expression => (expression.is_a?(String) ? "'#{expression}'" : expression)
  }
end

#ruby_when_condition(condition) ⇒ Object



1276
1277
1278
1279
1280
1281
1282
1283
# File 'lib/trxl/trxl_grammar.rb', line 1276

def ruby_when_condition(condition)
  case condition
  when nil then "nil"
  when String then "'#{condition}'"
  else
    condition
  end
end