Module: Trxl::MultFunction2

Defined in:
lib/trxl/trxl_grammar.rb

Instance Method Summary collapse

Instance Method Details

#eval(env = Environment.new) ⇒ Object



6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
# File 'lib/trxl/trxl_grammar.rb', line 6509

def eval(env = Environment.new)
  values = evaluated_expressions(env).compact
  return 0 if values.size == 0
  values.inject(1) do |sum, val|
    sum * if val.is_a?(Array)
      val.flatten.compact.inject(1) { |next_sum, v| next_sum * v }
    else
      val
    end
  end
end

#evaluated_expressions(env = Environment.new) ⇒ Object



6521
6522
6523
# File 'lib/trxl/trxl_grammar.rb', line 6521

def evaluated_expressions(env = Environment.new)
  expressions.map { |e| e.eval(env) }
end

#expressionsObject



6525
6526
6527
# File 'lib/trxl/trxl_grammar.rb', line 6525

def expressions
  [ expression ] + more_expressions.elements.map { |e| e.expression }
end