Module: Trxl::SumFunction2
- Defined in:
- lib/trxl/trxl_grammar.rb
Instance Method Summary collapse
- #eval(env = Environment.new) ⇒ Object
- #evaluated_expressions(env = Environment.new) ⇒ Object
- #expressions ⇒ Object
Instance Method Details
#eval(env = Environment.new) ⇒ Object
6269 6270 6271 6272 6273 6274 6275 6276 6277 |
# File 'lib/trxl/trxl_grammar.rb', line 6269 def eval(env = Environment.new) evaluated_expressions(env).compact.inject(0) do |sum, val| sum + if val.is_a?(Array) val.flatten.compact.inject(0) { |next_sum, v| next_sum + v } else val end end end |
#evaluated_expressions(env = Environment.new) ⇒ Object
6279 6280 6281 |
# File 'lib/trxl/trxl_grammar.rb', line 6279 def evaluated_expressions(env = Environment.new) expressions.map { |e| e.eval(env) } end |
#expressions ⇒ Object
6283 6284 6285 |
# File 'lib/trxl/trxl_grammar.rb', line 6283 def expressions [ expression ] + more_expressions.elements.map { |e| e.expression } end |